Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hello!!
how can we send a message from a client to another client in a client server architecture ?
i am trying to implement an algorithm in c++ in which i want to send message from each node to the neighbouring nodes for some reason and to further implementation ..i m confused how to do dis because i have never worked with network programming before in c. i have studied some codes but they are either sending message from server to client or client to server...can someone help please?
Posted

You already posted this question here[^]; please post in one forum only.
 
Share this answer
 
Someone done this berore, so just think of using some TCP based protocol. There are many of them, such as RPC, DCOM, CORBA, SOAP... But there is no more interesting thing in the world than reinventing the wheel. So, not a problem. You can your own. For study purposes it is very good exercise.
 
Share this answer
 
In classic client server, you cannot send a message from client to client directly.
This is simply because there is no TCP/UDP/etc connection between 2 clients.

Your server has to relay messages between 2 clients somehow.
You can do it this way:
1) In messages from client to server, have a simple int or bool field meaning "destination", for example, 1 for server, 0 for client.
2) If the server gets a message with this field indicating it is for another client, send it "as is" into the connection with that client WITHOUT PROCESSING - e.g. it acts as a simple data relay.

Client1->Server->Client2
Client2->Server->Client1

If you have more than 2 clients, you can easily extend this as needed. You can support situations where your messages are "broadcast" (one client talks to all other clients) or "point to point" (one client talks to one other client).

By the way, there are peer to peer protocols built on top of TCP/IP eg. on app layer of OSI model, but still, each side has a client and a server "part" simultaneosly.
 
Share this answer
 
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900