accept() method and tcp/ip handshake
Asked Answered
B

3

5

I use java ServerSocket class for server application. Does accept() method participate in tcp/ip handshake?

As I see in tcp/ip dump and from command netstat, clients establish connections with before accept method is called and return Socket object.

Is it java issue, or I do not understand accept() semantics?

Blackshear answered 19/1, 2010 at 22:35 Comment(0)
S
7

Generally in Unix, if you mark the socket with listen(), the operating system starts accepting the connections. When you call the accept() function, the operating system simply hands over the already opened connection. Listen takes a parameter which allows you to specify how many 'non-accepted' open connections the OS allows (i.e. the size of queue).

Semblable answered 19/1, 2010 at 22:38 Comment(0)
A
1

The accept method does not actively participate in the handshake, per se. The sending and receiving of the messages is implemented in the TCP/IP protocol stack, typically in the OS kernel space.

However, the accept() method is involved in the sense that the TCP/IP stack will only send the SYN-ACK message if some process has an accept() call active for a socket bound with the relevant IP address and port. When the three-way handshake is completed, the accept() method call will complete.

If no process calls accept() in time the incoming SYN message will be dropped by the kernel and the remote client will eventually time out the connection attempt. (On the other hand, if the IP address / port is not bound, then the kernel is likely to respond with a RST, and the remote client will see a "connection refused".)

Arrogate answered 19/1, 2010 at 22:46 Comment(0)
S
0

Accept returns only after the client and server are connected (handshake, etc).

Stuartstub answered 19/1, 2010 at 22:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.