Single vs. Dual Sockets In Network Programming
The question is about network programming, more precisely servers. Let's suppose there is a server which handles a lot of connections, and thus has a listening socket. There obviously exists a single instance of such a socket, that's clear. Now I've seen designs which use (a)one socket for every connection, both for incoming and outgoing data, a开发者_运维知识库nd (b)two sockets, one for the incoming data, one for the outgoing data. What makes one or the other design more preferrable? What are the possible reasons / usecases for these two designs? The programs I was referring to were actually instant messengers (two of them), but this theoretically applies to any multiple-connection server (any server, then.)
Hope this question is not too generic, I don't know a lot about network programming at the moment, so asking this. Rapid Googling didn't help either.
TCP and UDP Sockets are full duplex. There is no reason whatsoever to use separate sockets for input from and output to the same client. It is just wastefully using up kernel resources at double the rate.
精彩评论