本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
... if you want to create a TCP server, you call socket() first to create a socket. Then you fill out the sockaddr structure (with IP address and port number) and call bind() to assign the address and port to the socket. Then you call listen() to convert the socket into a passive socket so that it will accept incoming connections. That's why the socket is called "listenning socket" up until now.
Next you call accept() to retrieve the next completed connection and you get a connected socket. This is different from the listenning socket.
From "UNIX Network Programming Vol 1" (by Richard Stevens) P.100:
"A given server normally creates only one listenning socket, which then exists for the lifetime of the server. The kernel then creates one connected socket for each client connection that is accepted (which the TCP three-way handshake completes). When the server is finished serving the given client, the connected socket is closed."
So that's why I say, only connected socket can be used as the identifier of a TCP sesssion, not listenning socket.
更多精彩文章及讨论，请光临枫下论坛. 网址: rolia.net/zh