Socket 学习笔记

来源:互联网 发布:搜狐网络大厦11层 编辑:程序博客网 时间:2024/06/06 07:50

1      Socket 知识

1.1      Listen()

To accept connections, the socket is first created with Create,a backlog for incoming connections is specified withListen, and thenthe connections are accepted with Accept.Listen applies only to socketsthat support connections, that is, those of typeSOCK_STREAM. Thissocket is put into "passive" mode where incoming connections areacknowledged and queued pending acceptance by the process.

This function is typically used byservers (or any application that wants to accept connections) that could havemore than one connection request at a time: if a connection request arriveswith the queue full, the client will receive an error with an indication of WSAECONNREFUSED.

Listen attempts to continue to functionrationally when there are no available ports (descriptors). It will acceptconnections until the queue is emptied. If ports become available, a later calltoListen or Accept will refill the queue to the current or mostrecent "backlog," if possible, and resume listening for incomingconnections.