Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 May : TIdTCPServer-Client Can I send to the client when I want to

www.cryer.info
Managed Newsgroup Archive

TIdTCPServer-Client Can I send to the client when I want to

Subject:TIdTCPServer-Client Can I send to the client when I want to
Posted by:"PeaShooter_OMO" (jacquesv..@homemail.co.za)
Date:Tue, 9 May 2006 00:53:17

I have seen quite a few examples on how to write Client/Server apps with
TIdTCPServer and TIdTCpClient and most do the following:

1. The client connects to the server.
2. The client asks for something.
3. The server reads what it received (what the client wants) and responds.
4. The client reads it and do whatever it wants with it
5. The client disconnects.

This usually happens in one procedure at the client-end and usually the
server will handle its side in its OnExecute event. Hopefully I am correct
so far!!...

I would like to do things a bit differently, so how do I send something (a
string for example) to a TIdTCPClient from a TIdTCPServer whenever needed
(when something happens on the server) and not when the clients requests
something, and is there a way for the TIdTCPClient to know that it has
text waiting to be read without using a timer to poll for incoming?

Basically it must work as follows:

1. The client connects
2. The client asks for something and receives a response if needed from the
server. (optional)

...time goes by

3. Something happens on the server and it sends something to the client
4. Client sees (hopefully by an event) that there is something to be read
and reads it and responds to it if needed.

...time goes by and steps 3 and 4 might repeat .

5. Disconnection takes place when no comms is needed anymore.

Obviously the above is not confined to one procedure and one Execute at the
server side.

Is this possible and how will it be done and will I keep the client
connections open for the whole time in case the server wants to send
something to the client
because the server obviously cannot send to the client whenever it wants to
if the client has disconnected?

I was thinking about having both TIdTCPClient and TIdTCPServer components on
both the Client and Server sides but with some more thought it seemed
obvious that it would be tedious and most probably stupid to do that. I am
sure that my situation can be handled by Indy with a TIdTCPClient component
at the Client side and a TIdTCPServer component at the Server side.

I do not mind in reading help, info or references, so a nudge into a
direction would be much appreciated.

Thank you

Replies:

www.cryer.info
Managed Newsgroup Archive