Recent

Author Topic: problem when stopping a TTCPServer with connected customers  (Read 8091 times)

chubb

  • Newbie
  • Posts: 2
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

  • Administrator
  • Hero Member
  • *
  • Posts: 2583
Re: problem when stopping a TTCPServer with connected customers
« Reply #1 on: May 13, 2010, 03:55:20 pm »
without simple sample code it is hard to tell whats going wrong.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: problem when stopping a TTCPServer with connected customers
« Reply #2 on: May 13, 2010, 07:02:03 pm »
Just a wild guess: Synapse has a property EnableReuse(Value: Boolean);
http://synapse.ararat.cz/doc/help/blcksock.TBlockSocket.html#EnableReuse

From http://linux.die.net/man/7/socket
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.
« Last Edit: May 13, 2010, 07:18:18 pm by theo »

chubb

  • Newbie
  • Posts: 2
Re: problem when stopping a TTCPServer with connected customers
« Reply #3 on: May 17, 2010, 05:59:23 am »
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)

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".

Thank you everybody

Good day

 

TinyPortal © 2005-2018