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 tell when a socket is closed on the other end?

0 Answers  


What is the purpose of socket?

0 Answers  


Where can a get a library for programming sockets?

1 Answers  


Are sockets files?

0 Answers  


What is a deep well socket?

0 Answers  






When should I use shutdown()?

1 Answers   Wipro,


How many sockets can a port have?

0 Answers  


What is socket programming in java?

0 Answers  


What are socket exceptions? What is out-of-band data?

1 Answers  


Is a socket a file?

0 Answers  


How can I be sure that UDP messages are received in order?

1 Answers  


Where is the socket located?

0 Answers  


Categories