Forum > Networking and Web Programming

problem when stopping a TTCPServer with connected customers



I try to use a TCP server, Windows and Linux. My choice is focused on the TTCPServer.

I managed to use it normally, mode bmThreadBlocking.

When a client connects to my server I keep it in OnAccept function is called when I received the event of the same name. When the client disconnects, I lot of my office OnAccept. Up until this no problem.

When I turn off the server and restarts without any client connected to him, everything goes well. By cons, if I switch off the server when a client is connected, the client is connected and when I try to restart the server it does not work.

So I tried to force the disconnection of customers before closing the server (at the connection I store client in a collection), the customer logs out fine but when I restart the server, I get an error on bind ( or ENXIO No such device or address).

I should mention that this error occurs only on Linux, the same code works on Windows without problem.

Thank you in advance


without simple sample code it is hard to tell whats going wrong.

Just a wild guess: Synapse has a property EnableReuse(Value: Boolean);


--- Quote ---Linux will only allow port re-use with the SO_REUSEADDR option when this option was set both in the previous program that performed a bind() to the port and in the program that wants to re-use the port. This differs from some implementations (e.g., FreeBSD) where only the later program needs to set the SO_REUSEADDR option. Typically this difference is invisible, since, for example, a server program is designed to always set this option.
--- End quote ---


Thank you theo, after some research using the links provided, I discovered that there is a parameter 'SO_REUSEADDR' to specify that we can reuse the socket immediately

Below is a part from the forum (

--- Quote ---The TCP RFC describing states that after closing a socket, it must remain "useless" for a certain time (typically the maximum round-trip time set for a TCP connection), only to avoid reopening the same ports, it recovers bits of the previous connection packets that were in transit through the maze of the Internet.

After completing a socket, looks with "netstat-ap - ip" the list of existing sockets in the system: those that are closed are in such a state of "TIME_WAIT".
--- End quote ---

Thank you everybody

Good day


[0] Message Index

Go to full version