I have a few basic questions about sockets programming. I am trying to write a program (in C, linux) in which several client processes connect to a server process and also the clients need to connect to themselves. Though the clients would reside on separate machines, them being on the same machine is also a case. These are my questions.
-
Can two client processes communicate with each other on the separate port? In that case none of them listens to a port (like how the server does). They just connect to a port using a socket and talk to each other. Is that possible?
-
If not, how can I make communication between the clients?
Any idea on this would be of help. Thanks.
no, in TCP this is not possible. When establishing the connection in TCP, you are always connecting to listening port, so one of the clients must listen.
one of the clients needs to open listening port, but which one? Use the server as an arbiter! Employ a protocol where server moderates:
And if you were asking if two processes can listen on the same port on the same machine, then the answer is no. But using the above protocol you can avoid this situation.