Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jun : Re: TCP client/server
| Subject: | Re: TCP client/server |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Tue, 6 Jun 2006 10:05:22 |
"Richard Bibby" <richard.bibby@profdoc.se> wrote in message
news:4485562d@newsgroups.borland.com...
> the dTCPServer1Execute(AThread: TIdPeerThread) event executes
> TWICE for the single WriteLn in the client, and its the second time
> that I get the exception.
If you are getting the exception on the server side, then that is perfectly
normal, as I explained to Jamie.
Indy is NOT an event driven library. The OnExecute event is triggered in a
loop for the lifetime of the thread. It is NOT triggered whenever data
arrives from the client. When the event handler exits, it is immediately
triggered again, regardless of the socket's current state. So, if you do a
single call to ReadLn() the first time, it receives the data from the
client's single call to WriteLn(). The next time it is triggered, the
client has closed its end of the connection, so the ReadLn() on the server
throws an exception the second time it is called. That is perfectly normal
behavior, and is how Indy is designed to work. Just let the exception
happen. Don't block it from escaping the event handler (if you want to use
a try..except block to handle the exception, just make sure that you
re-throw the exception when your code is done). TIdTCPServer will handle
the exception by stopping the thread and cleaning up its side of the
connection.
Gambit