Link to home
Start Free TrialLog in
Avatar of rafaelrgl
rafaelrgl

asked on

Problem with send information to server( tidtcpserver - tidtcpclient )

My question is, how the server know which client is sending a message? and how to make shure the message was receive?

1) I have application server using tidtcpserver (indy 9)
2) 15 clients connected to the server.
3) client number 14 send some message using: tidtcpclient.writeln('test');
    at same time other client send another message, how to the server knows which message is from client 14???


Avatar of 2266180
2266180
Flag of United States of America image

the onexecute event of the tcpserver component is fired. it has a parameter: athread. you can use athread,conneciton to read/write to the connection. that event is fired in the thread of each connection so even though you only see one event, it is executed in the context of all 15 connection passing as the parameter the thread for the specific connection.

procedure serverexecute(athread:tidpeerthread);
begin
  log(athread.connection.readln());
  athread.connection.writeln('boo');  
end;
will log test from client 14 and send "boo" to the client 14.
Avatar of rafaelrgl
rafaelrgl

ASKER

what happening to know if the server receive all messeges from the client?

if the client send this:

idtpclient.writeln('first message');
idtpclient.writeln('second message');
idtpclient.writeln('third message');

how to make shure that three message was received?
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MerijnB
for a reliable tcp connection you will have to implement a keepalive / watchdog mechanism. This is because it's quite possible the connection drops and one of both sides doesn't notice this!
If 2 clients send a message at same time using : writeln('ldkfs');, than what happening to know which message is from?
you are not following me: EVERY connection is in DIFFERENT thread. nothing is overlapping. at all time you know exactly which client sent a message.
that onexecute event, even if appears one time it is being executed for every thread in the context of that thread.

I don't know how to explain this better :) maybe give a clear example of what you dont know what and how works.
or better yet try it on examples to see yourself how things work. dunno what to say...