Discussion:
Winsock: Stop accepting new connections?
(too old to reply)
kimmerkc
2007-09-24 04:02:32 UTC
Permalink
Raw Message
Posted to borland.public.delphi.internet.winsock with no response.
I'm hoping someone here might have an idea:

I have a server application that uses TServerSocket and its associates
to receive incoming TCP/IP connections from multiple client
applications. We actually have several instances of this server
application listening on different ports and/or on different machines,
and traffic is directed to each instance via a Network Load Balancing
utility.

What I would like to do is put a button on my application that will
cause the app to stop listening for new connections without
terminating the existing connections. This would enable support staff
to slowly take one instance out of the pool without having to
interrupt active users.

However, I haven't a clue how to do this. I could probably add code
in the OnGetSocket or OnConnecting events to refuse the connection,
but this would result in the client receiving an error and having to
try again, which I do not want. The NLB utility I am using will not
send connections to a port that is not listening, so that is what I
want to do. The TServerSocket object is NonBlocking, but changing
this to a multi-threaded app has been on my to do list for a while, so
if I must do so to gain this functionality, I will. I can also get
more information on the NLB utility, but right now I don't even really
know what to ask.

Can someone point me in the right direction?

Thanks,
Kimberly
kimmerkc
2007-09-28 21:47:14 UTC
Permalink
Raw Message
From a previous discussion I found on the subject, it appears that one
major difference is that Indy does not detect that a client has
disconnected. This will be a problem for me, but I've found some demo
code to show how to do this.

Also, here is some more information about my specific application that
may help folks to make a recommendation:

Currently using TServerSocket with ServerType := stNonBlocking

Multiple Clients connect simultaneously. In OnGetSocket, I create a
custom socket object (derived from TServerClientWinSocket) to handle
the individual connection. I don't do anything fancy with threads
here and do not expect that my code is threadsafe:

procedure TMainFrm.ServerSockGetSocket(Sender: TObject; Socket:
Integer;
var ClientSocket: TServerClientWinSocket);
begin
ClientSocket := tPalmSock.Create(Socket, TServerWinSocket(Sender),
Database, LogDB, ETDb);
end;

All communication is controlled from the client, synchronously. So
the server listens, receives a request for a connection, then reads,
processes and responds. All writing back to the client is handled in
the ServerSocket.OnRead event like so:

procedure TMainFrm.ServerSockClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
with Socket as tPalmSock do begin
...
//read data here. When complete message received
if size = CybMsg.ContentLength then begin
try
dbClient.ProcessRequest(CybMsg);
...
repeat
bytesRead := SendBuf(CybMsg.PRespBody^,
CybMsg.ContentLength);
until bytesRead > -1;
...

Would this work in Indy? Can I do something in OnGetSocket to handle
multiple threads? Do I even need to do so?

Kimberly

Loading...