Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
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.
0 · ·