|Subject:||Creating TCP server with blocking Indy components?|
|Posted by:||Bo Berglund (bo.berglu…@telia.com)|
|Date:||Fri, 23 Mar 2007|
I have been off and on making some programs that used the
TServerSocket and TClientSocket components that came with Delphi up to
(I have been on D1, D2, D3, D4, D5, D6, D7 over the years....)
These components implement the communication using non-blocking
sockets and fire off events on reception of data from the other side.
Now I see that these components won't live any longer and I need
something else. Indy 9 is what is supplied by Borland with Delphi7,
but these components are blocking and I can't for the life of me
understand how I can ever get them to work...
Problem I now face:
I need to create a connection point in an automation system where a
machine tool will connect to my software and then accept commands from
me. The structure is weird, but is dictated by the tool maker who
wants to make the connection...
So I am required to build a TCP server, which will listen on two
ports, one is a "command" port and the other is a "state" port.
On the main port the tool will connect to me and I am required to send
back a command that basically tells the tool to also connect to the
It will do so and then send a connect data packet on the "state"
socket. After this it will wait for commands from me on the "command"
socket and send event data on the "state" socket.
All data packets are strings formatted as XML (again dictade by the
tool maker). There is as far as I have seen no special termination
character, because the end bracket (>) repeats many times in the
message text. The closing tag of the XML string is what identifies the
end of message: </msg>. But this is a 6-char string....
Now my trouble really begins...
The examples I have seen do not clearly show how the server (my
program) can *send* commands to the connected client and retrieve the
responses. Note that the examples do it the other way, a client
connects to a server and then sends some command that gets replied to
by the server. In this case after connection it is the server's task
to "push" commands over to the client.
What methods on the server should I use to actually send a string to
the connected client and retrieve its response???
The client (the tool) is supposed to send packets of data on the
"state" socket at asynchronous intervals. Since Indy is blocking and
thus there are no events, how can I ever retrieve these messages on
the server side????
In the old days I would simply collect the incoming data in the
receive event and when the message is complete as determined by the
length of the data (binary transfers) or some termination word, I
would process the message.
Without receive events, how can it be done?
Grateful for how-to type replies, I am not really comfortable with the
Finally, my Indy with D7 is 9.0.10, must I upgrade in order to create
the TCP server outlined above?