Re: TIdHTTPServer/Client reusing socket

Giganews Newsgroups
Subject:Re: TIdHTTPServer/Client reusing socket
Posted by: Remy Lebeau (no.spam@no.spam.com)
Date:Fri, 8 May 2009

"Alan Chan" <akirab…@hotmail.com> wrote in message
news:1145…@forums.codegear.com...

> Hi there. I am using Delphi 2009 and building a simple HTTP server
> for receving messages from clients (also use  TIdHTTP). After some
> heavy testing by using only one client, the server will soon run out of
> ports with an error message "address or port are already in use".
>
> netstat -n shows there are a large amount of TIME_WAIT entries.

That would only be possible if you are deactivating and reactivating the
server in between client connections.  Even though there may be TIME_WAIT
entries for each client that connected to the server, the server only has 1
listening socket per local IP/Port pair, and does not create new listening
sockets in between connections.  The error you mention can only occur when
new sockets are being created and bound.

Sounds like you need to consider using HTTP v1.1 instead of HTTP v1.0 (if
you are not already) so that connections are not closed as often.  An HTTP
v1.0 server always closes a connection after sending a reply, unless the
client explitically asks the server not to.  An HTTP v1.1 server does not
close a connection after sending a reply, unless the client explitically
asks the server to, or if the client disconnects on its end after reading
the reply.

> I have also tried setting ReuseSocket to rsTrue on both server and
> client but there is no real difference.

ReuseSocket only makes sense to use on the client side if you are using the
BoundIP and BoundPort properties.  Otherwise, the client always binds to a
random IP/Port for each new connection.

ReuseSocket on the server side would not help you in this situation if you
are not reactivating the server in between client connections.

--
Remy Lebeau (TeamB)

Replies

In response to

TIdHTTPServer/Client reusing socket posted by Alan Chan on Fri, 8 May 2009