283
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
a reconnect from any host or port. Basically, this means, that whatever connection
is in progress, it will be interrupted and replaced by any other incoming
connection.
Do not use reconnects for HTTP sockets!
Reconnects and HTTP do not play nicely together. When you request an HTML
page, several simultaneous HTTP requests may be generated (one for the page
itself, several -- for pictures on this page, etc.). All these requests will use a
separate TCP socket, so multiple sockets will be opened (almost) at the same time.
Now, what will happen if even just one of your application's "HTML" sockets has
reconnects enabled? This single socket will intercept all HTML requests. So, if
loading the HTML page needed 3 separate requests and TCP sessions, this socket
will get them all -- and each next session opening will discard the previous one.
Result won't be pretty!
Understanding UDP Reconnects and Port Switchover
For UDP "connections", there is also such a thing as reconnects. Due to a very
different nature of UDP (compared to TCP), reconnects for UDP must be explained
separately. Additionally, we need to introduce something called "port switchover".
Port switchover explained
With TCP, each side of the connection uses a single port both to send and receive
data. With UDP, this doesn't have to be the case. The sock object, when it is
engaged in a connection, can receive the data from one port but send the data to a
different port!
When port switchover is disabled, the socket always addresses its outgoing UDP
datagrams to the port, specified by the
property. When port
switchover is enabled, the socket will address its outgoing datagrams to the port
from which the most recent incoming datagram was received!
Notice, that we did not say anything about the IP switchover- so far we have only
discussed ports.
UDP reconnects
Just like with TCP, the
property defines, for UDP, what kind of
incoming UDP datagram will be able to make the socket forget about its previous
"connection" and switch to the new one. You have two choices: either define that
reconnects are only accepted from a specific IP but any port or choose reconnects
to be accepted from any IP and any port. Combine this with two options for port
switchover and you have four combinations- four options for the sock.reconmode
property. All this is best understood on the example.
Example: PL_SOCK_RECONMODE_0
Setup:
sock.protocol= PL_SOCK_PROTOCOL_UDP
'we are dealing with UDP
sock.inconmode= PL_SOCK_INCONMODE_ANY_IPPORT
sock.reconmode= PL_SOCK_RECONMODE_
0
'reconnects accepted from the same IP,
any port, port switchover off
sock.localportlist=
"3000"
sock.targetport=
"900"
360
345