Strange socket problem - SOCK_CLOSE doesn't properly close sockets?

Previous topic - Next topic

Moebius

Hi, sorry to submit another bug report, but I've been having problems with closing and reopening sockets...  Please look to the following:
Code (glbasic) Select
// 1) Try with the 'close then reopen' commented.  Everything works as expected.

// 2) Try with the 'close then reopen' uncommented.  Only broadcast messages get through.

// 3) Do the same and try pressing 'enter'.  It's as if SOCK_SHUTDOWN properly closes the sockets, and SOCK_CLOSE doesn't...



LOCAL HostS%, ClientS%

SOCK_INIT()

HostS% = SOCK_UDPOPEN(11111)
ClientS% = SOCK_UDPOPEN(11112)



// If the socket is closed and then reopened, only broadcast messages are received.
//
// Try commmenting and uncommenting this:
//---------------------------------------

SOCK_CLOSE(ClientS%)
ClientS% = SOCK_UDPOPEN(11112)

//---------------------------------------




LOCAL Msg$

WHILE NOT KEY(1)


// Press spacebar to send a broadcast and specific message:
IF KEY(57)

SOCK_UDPSEND(HostS, "Broadcast\r\n", SOCK_GETIP("255.255.255.255"), 11112)
SOCK_UDPSEND(HostS, "Specific\r\n", SOCK_GETIP("127.0.0.1"), 11112)

WHILE KEY(57); WEND

ENDIF

// Press enter to 'reset' networking - after this both broadcasted and specific messages get through.
// It's as if SOCK_SHUTDOWN properly unregisters all of the sockets, but SOCK_CLOSE doesn't.
IF KEY(28)

SOCK_SHUTDOWN
SOCK_INIT()

HostS% = SOCK_UDPOPEN(11111)
ClientS% = SOCK_UDPOPEN(11112)

ENDIF

IF SOCK_RECV(ClientS, Msg$, 16) THEN DEBUG Msg$

SHOWSCREEN

WEND



END


Basically, it appears that SOCK_CLOSE isn't properly 'unregistering' the socket - or something like that.  I first got onto this because, I've found, two different instances of the same program can use the same port for receiving messages if, and only if, the message is broadcasted.  A non-broadcasted message is received only by the program that registered the port first.
It seems to be a similar thing with sockets in one program.  If you create and then close a socket, it is as if the messages sent to that port are received by the first socket - which was closed.  The newly created socket will only receive broadcast messages.

This was really annoying and took a while to figure out, but I got around this easily by initialising the sockets just once, and so has no personal priority, but I'd might as well report it anyway.

Platform-wise, it occurs on Windows and (99% sure) OSX and iOS, but Android is completely fine.
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Kitty Hello


Moebius

Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary