My understanding of TCP in Java is that, while you can multithread handling data transmissions on a socket, you can only establish one connection at a time. Is this true? If not, how would you implement a server that can establish multiple connections simultaneously on the same address and port.
i.e If a client was to try and establish a connection to the server, but is connecting over a very unstable network, would the server have to wait for the connection handshake to complete before being able to accept a connection from another client?
This aspect of the TCP protocol is addressed by the listen backlog. On linux at least, half-open connections for a server are queued pending completion after which they are ready to accept. The maximum number of half-open connections that a server can handle is capped by the OS. On Linux you can see what the cap is by examining a
/proc
entry. For example on a RHEL 6 VM:A malicious entity can exploit this by launching a SYN_FLOOD attack that will fill up the listen backlog and prevent your server from accepting new connections. Mitigating this type of attack (especially when performed by a botnet) is extremely difficult but there are some basic defences as well as some expensive paid services out there.