BUG: DatagramSocket::bindToPort returns true even if it really fails, at least on windows


#1

After updating JUCE To the latest download (4.3) from the Projucer, the following bug appeared. It still also happens with the latest tip from github, which I upgraded to to see if the bug was fixed…

Previously in my code “bool success = socket->bindToPort(port);” worked - i.e., success would be true if the port was successfully bound by the DatagramSocket, and false if the port was already in use. Now however, it always just returns true, even if the port is taken by another socket, and the new one in reality isn’t using the port at all.

Of course(?), each DatagramSocket is initialized and used in its own thread.

I’m not exactly sure when this was introduced, but I am certain that a few updates ago it used to work fine.

This happens on Windows 10, building for win32 with VS 2013.

Best,
Ilias B.


#2

Is that the latest tip on the develop or master branch?


#3

Hi!

I wasn’t aware there were two different branches - I got it from here: https://github.com/julianstorer/JUCE/

…So, the master branch apparently.


#4

Sockets are notoriously difficult to handle in a cross platform way.

Does doing

socket->setEnablePortReuse (false);

before binding fix things?


#5

That did the trick, thank you!

I guess that must have been switched from default off to default on, considering my code used to work - I didn’t even know it existed.

Note however that previously, when I hadn’t set this to false, the two sockets I had opened with the same port were not both receiving, only the first. The second said it opened successfully but received nothing.

Thanks again!