Search code examples
javasocketstcphandshaking

accept() method and tcp/ip handshake


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?


Solution

  • 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).