tirbanqs
asked on
sending and receiving data from server to client and vice versa using indy9
Hi all!
How can a server send data to client? Like if the server wants to logoff the clients station...
And also if the client wants to logoff, how can the client send data to the server.
All i need is the sending process or i mean how can i trigger the server station to client station and vice versa.
Im going to use Delphi 7 and Indy 9.
I dont know if you guys understand me. Sorry for my english.
By the way, Im making an internet cafe program.
Thanks
How can a server send data to client? Like if the server wants to logoff the clients station...
And also if the client wants to logoff, how can the client send data to the server.
All i need is the sending process or i mean how can i trigger the server station to client station and vice versa.
Im going to use Delphi 7 and Indy 9.
I dont know if you guys understand me. Sorry for my english.
By the way, Im making an internet cafe program.
Thanks
ASKER
Thanks. But i need a more detailed code with my problem. I havent found the exact server to client data sending like logging off the clients station.
to send data to the client within the server's "OnExecute" code you can just go
AThread.Connection.WriteLn ('Please go away now');
and the client could see that and disconnect
s := IdTCPCLient1.readLn;
if s = 'Please go away now' then IdTCPClient1.Disconnect;
of course, you could just have the server disconnect the client...
AThread.Connection.Disconn ect;
If you need to send a message to a client, but you are not within the onececute event, you could iterate through all the clients and send the message that way
eg.
with IdTCPServer1.Threads.LockL ist do
try
for i := 0 to Count - 1 do
begin
if (
(TIdPeerThread(Items[i]).C onnection. Socket.Bin ding.PeerI P = '127.0.0.1')
{if you know the port you wish to talk to, you could also check
and (TIdPeerThread(Items[i]).C onnection. Socket.Bin ding.PeerP ort = 12345)
Normally I'd have an "id" or "name" property set in teh ".Data" pointer (as an object) so I'd just find it that way
) then TIdPeerThread(Items[i]).Co nnection.W riteln('I' 'm talking to you');
finally
IdTCPServer1.Threads.UnLoc kList;
end;
I do not recall the commands to "logoff" a user's machine, but I think it's something like
ExitWindowsEx(EWX_LOGOFF + EWX_FORCE, 0);
but if you still wanted to be able to commiunicate if the client logs their machine off, then make this a service (which will run even if no one is logged on to the machine)
AThread.Connection.WriteLn
and the client could see that and disconnect
s := IdTCPCLient1.readLn;
if s = 'Please go away now' then IdTCPClient1.Disconnect;
of course, you could just have the server disconnect the client...
AThread.Connection.Disconn
If you need to send a message to a client, but you are not within the onececute event, you could iterate through all the clients and send the message that way
eg.
with IdTCPServer1.Threads.LockL
try
for i := 0 to Count - 1 do
begin
if (
(TIdPeerThread(Items[i]).C
{if you know the port you wish to talk to, you could also check
and (TIdPeerThread(Items[i]).C
Normally I'd have an "id" or "name" property set in teh ".Data" pointer (as an object) so I'd just find it that way
) then TIdPeerThread(Items[i]).Co
finally
IdTCPServer1.Threads.UnLoc
end;
I do not recall the commands to "logoff" a user's machine, but I think it's something like
ExitWindowsEx(EWX_LOGOFF + EWX_FORCE, 0);
but if you still wanted to be able to commiunicate if the client logs their machine off, then make this a service (which will run even if no one is logged on to the machine)
ASKER
Thanks. Can you give me a working project for the server and client.
Im still having trouble. I implemented the code but still the client didnt receive the data sent
by the server. Sorry. Ill raise the points to 400. Thanks :)
Send it to my email: tirbanx@gmail.com
Im still having trouble. I implemented the code but still the client didnt receive the data sent
by the server. Sorry. Ill raise the points to 400. Thanks :)
Send it to my email: tirbanx@gmail.com
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://adg.bmpcoe.org/IndySSL/
They have some good starter examples for you to learn from :o)