In C++, when I run (red alert! pseudo-code)
bind(s1, <local address:port1234>)
bind(s2, <local address:port1234>)
on two different UDP sockets (s1
and s2
each created with a call to socket()
) I get problems. In Linux (Ubuntu), the double binding seems to be fine. In Windows, however, the double binding fails, and the call to bind()
the second time for the same address returns != 0
.
I want to get the behavior I have on Windows on my Linux machine. Are there some settings I can work to get a "port busy" on Linux?
Please see bind and setsockopt. Unless you have invoked setsockopt with SO_REUSEADDR, then your invocation of bind with the same address should result in failure with EADDRINUSE.
That's not the behaviour I get on Linux. When I run the following test program, the second
bind
call fails withEADDRINUSE
:Are you sure about that? According to
man 7 ip
on my Linux box (fedora 9):There is no mention of an exception for UDP binding in either
man 7 ip
orman 7 udp
. (This does not prove anything, but non-documented behaviour in something as basic as this is ... surprising.)