Reputation: 740
I'm working on a project which is a server-client application based on WinSock in C++. I've done whatever needed for communicate between the server and the client that I am able to send and receive messages between them.
Now I need to know how to accomplish the client-to-client messaging part and how the work must be done. I only know that for instance if Client A and Client B need to communicate with each other, the client A must send the message to the server, server receives the message and send it to client B.
If this is the proper approach please help me to know how the server should know anything of of the receiver (which is the Client B in this case)?
Please let me know if I haven't explained clearly my problem.
Any help is appreciated.
Upvotes: 2
Views: 4337
Reputation: 329
Think the client-server communication as an old Radio communication.
iterate until end-of-communication command
so just imagine that talk is write
, and listen is read
B: read -> A: write
A: read -> B: write
remember to use a keyword to disconnect the 2 clients, or you could have some bad behaviour from the system calls
Upvotes: 1
Reputation: 663
One way to accomplish this is have one of the client to act as a server after some communication over actual server. You need to create a protocol of yours. That being said:
1- Client A: -Hey, Server!. Tell the Client B to create a comm server so I can communicate directly with him.
2- Server: -Hey, Client B!. Start a server instance and tell me the connection properties so i can relay it Client A, so he can connect to you.
3- Client B: -Hey, Server!. I'm ready to accept the connection request for Client A. Here's my connection properties...
4- Server: -Client A!! Here the connection properties of Client B. Take it or leave it... I'm done..
5- Client A: -Hey, Server B!.. Can i connect?..
That is the protocol.. So any client first initiates a request to server that includes the message type of "me, requesting to connect to client x..". Server commands the client x, client x responses, server relays the response to initiator client... And also you should implement the error handlings, denial policies or some other things you can think of in order to manage the whole protocol.
Upvotes: 7
Reputation: 2337
Unless I totally missed the point of the question. You need to define a couple new messages with all the details needed for A and B to talk and send it to both A and B and they need to receive/process the message and react accordingly.
Upvotes: 3