Incoming Connections on Multiple Sockets

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 a 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 sock. 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, reconnect, or new incoming connection, then this packet is discarded.


Example

Suppose we have the following setup:

Tibbo BASIC
sock.num= 0
sock.protocol= PL_SOCK_PROTOCOL_TCP
sock.inconmode= PL_SOCK_INCONMODE_SPECIFIC_IP_ANY_PORT 
sock.targetip="192.168.100.40"
sock.reconmode= PL_SOCK_RECONMODE_2
sock.localportlist= "1001"
 
sock.num=1
sock.protocol= PL_SOCK_PROTOCOL_TCP
sock.inconmode= PL_SOCK_INCONMODE_ANY_IPPORT 
sock.localportlist= "1001"
 
sock.num=2
sock.protocol= PL_SOCK_PROTOCOL_UDP
sock.inconmode= PL_SOCK_INCONMODE_ANY_IPPORT 
sock.localportlist= "2000"

Here is a sample sequence of incoming connections and how the setup above would handle them:

Incoming datagram

Socket reaction

Incoming TCP connection to port 1001 from host 192.168.100.40:29600

Connection will be accepted on socket 0 since this socket lists 1001 as one of the listening ports and this incoming connection request is from "correct" host.

Incoming TCP connection to port 1001 from host 192.168.100.40:29601

This will be taken as a reconnect on socket 0: this incoming connection is from the same host as the previous one and it targets the same port 1001.

Incoming TCP connection to port 1001 from host 192.168.100.41:900

Connection will be accepted on socket 1, because socket 0 is already engaged in a connection and this new connection request cannot be intepreted as a reconnect (different host).

Incoming UDP datagram to port 2000 from host 192.168.100.40:320

This datagram will be accepted on socket 2 and a "connection" will be opened.


Incoming Connections on Multiple Sockets

Example