286
Platforms
©2000-2008 Tibbo Technology Inc.
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 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
-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.
Example
Supposing, we have the following setup:
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
341