Good way to send/receive UDP packets?
invalid at example.com
Tue Jul 28 16:26:05 UTC 2020
On Tuesday, 28 July 2020 at 15:01:08 UTC, Kagamin wrote:
> On Monday, 27 July 2020 at 09:41:44 UTC, wjoe wrote:
>> But it's possible when bound with the socket option
>> SO_REUSEPORT (at least that's the name of the flag on linux
>> since 3.9).
> The docs say it can't be used to hijack an address.
>>This option must be set on each socket (including the first
>>socket) prior to calling bind(2) on the socket.
Nowhere did I claim that you could hijack a bound port but that
it's possible to reuse a port.
Nothing prevents a UDP library from setting that option
automatically or by default.
Nothing prevents any program to bind to a port with that option
Normal behavior doesn't matter - what matters is what the library
you're using and other programs are doing.
All of this doesn't change the fact that every program that has a
socket bound to the same port on the same address at the same
time will get the datagrams deliverd.
One way to handle this scenario is to bind your socket with the
reuse option unset.
That would be first come first served.
Problem not solved - you still need to consider the fact that
another program or server on a different PC/address in the
network can assume that their corresponding client is up and
running and wants to receive on that very port.
Due to the nature of UDP communication, the server needn't care
if this assumption is true and send datagrams to it which you
will receive instead.
More information about the Digitalmars-d-learn