i m making a messenger in linux. a command line application. here is a server and 2 clients.both the clients are connected to the server but not with each other. i want to connect those 2 clients with each other. i m the server. how can i do that?


plz tel me a way out.

thanx

i m making a messenger in linux. a command line application. here is a server and 2 clients.both the clients are connected to the server but not with each other. i want to connect those 2 clients with each other. i m the server. how can i do that?


plz tel me a way out.

thanx

In the server u have to maintain a list of the connected client sockets. U can send this list(with some alias for display as name say) to the clients. The clients will chose from the list and then u can try writting to that socket from the client itself.
I have never tried this in C/C++ though.
But i think u can give a try.
This was just a suggestion. I am not very sure about its workability.

ok. i got ur point. but one more question plz. only one client needs to connect with the other client. or both of the clients need to call the command connect() ? in other words i need to send that socket to only 1 client or to the both?

ok. i got ur point. but one more question plz. only one client needs to connect with the other client. or both of the clients need to call the command connect() ? in other words i need to send that socket to only 1 client or to the both?

don't do a connect() from a client to client directly.
A client will always connect to the central server. Design your protocol in a manner as follows:

client ----------- connect() ---------> server
........................................(add the incoming client socket to a list)
client <------(client socket list)--- server
client --------particular socket----> server
(choose from other socket list)
client <----------ack------------------ server
(now this client have the particular socket where to write which the other client will read from, so just start writting to this socket.)

**** The above is not a full fleged protocol because it is not sending any info to the other client.
So first design your protocol properly, then only u should go for the implementation.

U have to design different message formats, say MSG_ACK, MSG_SOCKLIST, MSG_TEXT, etc.

May that help.

commented: a very good and detailed answer. i got that very clear now. thnx a lot sir +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.