I'm trying to implement my own protocol over UDP.
As suggested by many manuals in Internet, it's better to avoid IP fragmentation by sending packets with their sizes less than MTU.
I wonder what is the best way to get the optimal size of the message? Should I somehow get MTU value (like this, for example) or should I just set it to smth like 1300 or 1400 and hope that it won't be less or change over time?
I heard that there are some problems with getting MTU value (https://en.wikipedia.org/wiki/Path_MTU_Discovery) and as far as I know it highly depends on the current route and other factors that can change over time.
The recommended size for IPv4 UDP is 576 octets. Each Internet router is supposed to guarantee an IPv4 MTU of at least that size, and since UDP is a connectionless, fire-and-forget, best-effort, no-guaranteed-delivery protocol, you will risk less data with each packet that may be lost, and there will be lost packets.
IPv6 has a minimum MTU requirement of 1280 octets, and no fragmentation in the path.