Incoming Connections on Multiple Sockets
|Top Previous Next|
So far, we have been talking about all kinds of incoming connections applied to a single socket. The fact is, the sock object supports up to 16 sockets which all can have a different setup. Just because an incoming connection is rejected or ignored on one socket does not mean that it won't be connected on another!
When the network packet is received by the sock object the latter attempts to find a socket for which this newly arrived packet is acceptable.
First, the sock object checks if the packet can be considered a part of any existing connection or a reconnection attempt for an existing connection. All sockets that are currently engaged in a connection are checked, starting from socket 0, then sock 1, 2, and up to sock.numofsock-1.
If it turns out that some socket can accept the packet as a part of current connection or an acceptable reconnection attempt then the search is over and the packet is "pronounced" to belong to this socket.
If it turns out that no socket currently engaged in a connection can accept the packet then the socket object checks all currently idle sockets to see if any of these sockets can accept this packet as a new incoming connection. Again, all idle sockets are checked, starting from socket 0, and up to sock.numofsock-1.
For TCP, a packet that can start such a new connection is a special "SYN" packet. For UDP, any incoming datagram that can be accepted by the socket (which depends on the socket setup) can start the new connection.
If the packet cannot be construed as a part of any existing connection, re-connect, or new incoming connection then this packet is discarded.
Supposing, we have the following setup:
Here is a sample sequence of incoming connections and how the setup above would handle them: