bind fails on socket

Hi! Here's my problem: I create, bind, set to listen a TCP socket (non-blocking mode). Then client connects, I accept connection, data is transferred properly. Now if client first disconnects and only then I close my application (closing data socket, then listening one) I can start this application again (i.e listen on the same port again) without any problems. However if close my application before client disconnects (still closing both data and listening sockets) I can not listen on the same port again for about 30-40 seconds (bind fails, system says port in use). After 30-40 seconds I can listen again. I use shutdown and close to close sockets and always first close data socket and only then listening one. Does anyone know why system thinks that port is still in use if close server application before client disconnects? Client, by the way, detects disconnect and quits too.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!