problem when stopping a TTCPServer with connected customers lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- chubb · 2010-05-11 04:57 Hello 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 Chubb ---------------------------------------------------------------------- Marc · 2010-05-13 13:55 without simple sample code it is hard to tell whats going wrong. ---------------------------------------------------------------------- theo · 2010-05-13 17:02 Just a wild guess: Synapse has a property EnableReuse(Value: Boolean); http://synapse.ararat.cz/doc/help/blcksock.TBlockSocket.html#EnableReu se From http://linux.die.net/man/7/socket QuoteLinux 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. ---------------------------------------------------------------------- chubb · 2010-05-17 03:59 Welcome 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 (http://linuxfr.org/forums/27/18820.html) QuoteThe 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". Thank you everybody Good day