Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jun : Re: TIDCmdTCPServer and TIDTCPClient
| Subject: | Re: TIDCmdTCPServer and TIDTCPClient |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Mon, 19 Jun 2006 10:35:37 |
"Roberto Colpani" <roberto.colpani@vetrariafratellicolpani.it> wrote in
message news:4496b83f@newsgroups.borland.com...
> If I want to send from my server to every my connected user a msg,
> on the server side, can I use this code?
Technically yes, though I have a couple of comments. See below.
> if ASender.Context.Connection.Socket.Binding.PeerIP <>
> TIdContext(AList[I]).Connection.Socket.Binding.PeerIP then
Rather than comparing the IP addresses, you should compare the TIdContext
pointers instead:
if ASender.Context <> TIdContext(AList[I])
> TIdContext(AList[I]).Connection.IOHandler.WriteLn('@something to
> read');
Do note that WriteLn() is a blocking method, like everything else in Indy.
For any of the clients is slow, or the connection has been broken
prematurely, WriteLn() will block for a long time, which in turn is going to
block not only the client that sent the original command, but all future
connections and disconnects since you are keeping the Contexts list locked.
> How can I intercept this message from my clientside?
With ReadLn(), obviously.
> It 's good idea having a timer that check every a second the
> IOHandler.ReadLn function of the TIDTCPClent?
ReadLn() is also a blocking function. If the connection is slow or broken,
it can block for a long time as well. That is not a good thing to do in the
context of the main thread. I would not suggest using a timer, but instead
you should move the ReadLn() to a worker thread instead.
Gambit