PDA

View Full Version : send message from server to client


shafrudin
12-20-2008, 03:54 PM
i use indy 9 in delphi and i got problem when i want to send message from server to client. server may have many client and server only need to sent any client but not all....
if client send message to server it will probably easy way because one client will only have single server...
please help me???

Nito
01-06-2009, 05:08 AM
From what I'm gathering from what you've written, you want to be able to SEND_DATA to a SINGLE client when they SEND_DATA to the server?

The way you would do this, is by using the array of clients you have connected to the sockets (I assume you created an array?).

USER(ARRAY) -> SEND_DATA
RECEIVE_DATA -> SERVER
DATA_PROCESS
SERVER -> SEND_DATA TO USER(ARRAY)

How it works, is that when a client connects to a server, an array number is created. This number is then associated with ONLY that client, so when data is sent back and forth you need to call that array and go through it accordingly.

Hope this helps.

-Nito

shafrudin
01-07-2009, 06:54 AM
no i dont mean like that. the problem is when single server has 2 clients A and B. When A send data to server and server will send data to B. please give the example in code too. thanks for your help... :confused:

Nito
01-07-2009, 07:10 AM
I don't know Pascal well enough to give you example code, Google will give you sufficient results of example source if you need to see reference code.

However, it's the same in any language, just different syntax. The same thing I told you before, would be applied whether you want to SEND_DATA to 1 or 100 clients. You have to code the Socket Array with functions to send to either one client or every client connected.

You need to learn how to handle received data. When working with Sockets, you can set it so that if it's a chat network, which I'm assuming is what you're attempting to write based on the " A -> Server -> B ". So say A sends data. Server receives it, and sends it to every client EXCEPT A, as it would be a waste to send a packet of data back to the client who sent it without making any changes. This can be accomplished by simply posting to the text field at the same time the data's been sent to the server.

This explanation should be enough to get you on the path you need to go. If you're writing a server/client based network, you obviously have some sort of grasp on the sockets. And I just defined EXACTLY what needs to be done, twice...

-Nito