Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TIdTCPServer vs. TServerSocket

225 views
Skip to first unread message

kimmerkc

unread,
Sep 28, 2007, 2:46:15 PM9/28/07
to
I have an app that listens for and deals with connections from
multiple clients using Delphi's TServerSocket VCL component. The app
is having some problems (too many to explain in this message) and I
suspect the Socket code could use an overhaul. I am looking into the
Indy components and wondering if they might be a better fit for my
purpose. So my questions are as follows:

1. What are the major differences between in Indy components and the
Delphi VCL components as far as TCP/IP Sockets and specifically
servers are concerned?

2. Has anyone her converted existing TServerSocket code to an Indy
component? If so, which component(s) did you choose? Why did you
choose to do so? And what tips would you have for someone attempting
the same feat?

Thanks,
Kimberly

kimmerkc

unread,
Sep 28, 2007, 5:53:33 PM9/28/07
to
>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

0 new messages