Why does connect() succeed even before my server did an accept()?



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

Post New Answer

More Unix Socket Programming Interview Questions

How can I write a multi-homed server?

0 Answers  


What is the difference between a socket and a port?

0 Answers  


Explain the TIME_WAIT state.

1 Answers  


How do I send [this] over a socket?

1 Answers  


What exactly does SO_REUSEADDR do?

1 Answers  






How can I listen on more than one port at a time?

1 Answers  


Why do I get connection refused when the server is not running?

1 Answers  


What is a socket file?

0 Answers  


How are unix domain sockets implemented?

0 Answers  


Why do we need sockets?

0 Answers  


What are the pros/cons of select(), non-blocking I/O and SIGIO?

0 Answers  


How does a socket work?

0 Answers  


Categories