Reputation: 25
I am new to socket programming and need some help regarding establishing a new peer-to-peer network. What I have now is say a Server A connected to clients B and C respectively simultaneously. I am using the select() API to establish this, and so far this is working(A can communicate with B and C independently.) What I now want is to make B and C communicate with each other directly; say B requests to connect to C without involving A. B and C would both still be connected to A, but they will have a peer-to-peer connection amongst themselves to be able to talk to each other. Any idea how this works? I have tried making my client program acts like a server too with calls to listen() and accept(); but it simply freezes my client.
I have a user interface to throw commands at the client/server, if you are wondering how am I implementing this.
Any help will be deeply appreciated.
Upvotes: 1
Views: 11178
Reputation: 1707
For TCP connections, one peer has to be passively listening and the other has to be actively connecting. (There is one exception, TCP simultaneous open, which is probably not what you want.) In your example, to establish a connection between B and C, you can do it the same way as in A and B. I.e. you can make B listen&accept, and C connect.
Why your client freezes? Printing error message and strace
are your friends.
Upvotes: 1