Why does connect() succeed even before my server did an accept()?
Answer / chaitanya
Once you have done a listen() call on your socket, the kernel is primed to accept connections on it. The usual UNIX implementation of this works by immediately completing the SYN handshake for any incoming valid SYN segments (connection attempts), creating the socket for the new connection, and keeping this new socket on an internal queue ready for the accept() call. So the socket is fully open before the accept is done.
The other factor in this is the 'backlog' parameter for listen(); that defines how many of these completed connections can be queued at one time. If the specified number is exceeded, then new incoming connects are simply ignored (which causes them to be retried).
| Is This Answer Correct ? | 0 Yes | 0 No |
How come only the first part of my datagram is getting through?
What is Mac, and how is it different from PC? Which one is better for professional users, and why
1 Answers Evolving Systems, IBM,
How can I force a socket to send the data in its buffer?
What does af mean in sockets?
Are sockets files?
of the socket? Does doing a connect() call affect the receive behaviour?
What is a socket address?
Why do we need sockets?
Why do not my sockets close?
What is the difference between connected and unconnected sockets?
Is a socket a file?
How do Sockets Work?