Rather it's just a hint to the stack about how many TCP connections can be accepted on the socket's port before the applicaiton code has invoked accept on that socket. Be aware that accept doesn't negotiate a TCP handshake, it just takes one of the already accepted connections out of the backlog queue or waits for one to arrive.
So if your backlog is 1 and your server thread isn't waiting on accept , than means that an incoming client connection will at least establish the TCP handshake. If you attempt to have two pending connections when the backlog queue is 1, the second client connection will likely timeout or be refused if the server code isn't actively invoking accept to promote those connections out of the backlog and into sockets.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
Learn more. What is the purpose of listen in Socket Programming? Asked 1 year, 11 months ago. Active 1 year, 11 months ago. This is the same number which appears on protocol field in the IP header of a packet. This is completely optional, but it helps in reuse of address and port.
Listen: int listen int sockfd, int backlog ; It puts the server socket in a passive mode, where it waits for the client to approach the server to make a connection. The backlog, defines the maximum length to which the queue of pending connections for sockfd may grow.
At this point, connection is established between client and server, and they are ready to transfer data. Skip to content. Change Language.
Related Articles. Table of Contents. One socket node listens on a particular port at an IP, while other socket reaches out to the other to form a connection. Server forms the listener socket while client reaches out to the server. State diagram for server and client model. This is the same number which appears on protocol field in the IP header of a packet. This helps in manipulating options for the socket referred by the file descriptor sockfd. This is completely optional, but it helps in reuse of address and port.
After creation of the socket, bind function binds the socket to the address and port number specified in addr custom data structure. It puts the server socket in a passive mode, where it waits for the client to approach the server to make a connection.
0コメント