I have a client/server connection over TCP 开发者_如何学Cusing send()
and recv()
. This is working in full duplex just fine. However, if I want a 3rd party to be able to join in mid session and communicate on this line, how is it accomplished? Do I need another socket?
Yes you need a second socket. TCP socket are connection oriented, so they are useful only to manage a single connection beetwen 2 hosts.
Typically you can use a socket open on a well known port to use for establish connection from clients to the server. Then, once the connection has been established, you can transfer it to another socket.
If you aren't restricted to TCP, IP multicast and other protocols layered on top of it could be an option depending on your application.
Another option might be to use UDP, which is connectionless. Each datagram will contain the sender. It's up to you, however, to construct a meaningful stream of conversation out of the unordered, unreliable datagrams.
精彩评论