290
Platforms
©2000-2008 Tibbo Technology Inc.
Incoming/outgoing datagram
Comment
Datagram with contents "ABC" sent as
broadcast to all stations on the
network segment
We now have the UDP "connection"
with... err... everybody on the
segment
Incoming UDP datagram from
192.168.100.41:20.
This is still a reconnect, but the socket
won't switch over to the IP-address of
the sender. Only port switchover will
take place!
Socket sends out another datagram-
still as a broadcast but this time to
port 20.
Port switchover happened because it is
allowed by the
.
Closing Connections
Passive TCP connection termination
When your socket is engaged in a TCP connection with another host on the
network, this host may choose to terminate the connection. This can be done
through a "graceful disconnect" sequence ("FIN-ACK-FIN-ACK") or through a reset
("RST" packet).
In both cases the socket will handle connection closing automatically, without any
help from your Tibbo BASIC program or the VM. In fact, the socket will accept
connection termination even when the VM is stopped (for example, it was paused
on your breakpoint). All communications are handled by the
, so
the socket does not need the VM to terminate the connection.
There is one intricate detail in the connection termination process that you will
have to understand clearly. When the VM is not running, the socket can
(active open) and can accept an active close. However, the
socket won't be able to accept another (next) incoming connection until the VM
has had a chance to run and execute the
event handler (see
).
Here is why. In many cases there is a need to perform certain actions (like, maybe,
clear some buffers, initialize variables, etc.) after the previous connection ends and
before the new one begins. Not letting the socket accept next connection before
your program has a chance to respond to connection termination is a way to
achieve this!
Actively closing TCP connections
A TCP connection can be closed, reset (aborted), or discarded using three different
methods-
,
.
The recommended (and polite!) way of closing a TCP connection is through the
sock.close method. This will initiate a proper closing sequence ("FIN-ACK-FIN-
ACK"), known as a "graceful disconnect".
Connection reset is slightly more "rude"- your socket will simply tell the other end
that "it is all over" (by sending the "RST" packet).
Finally, the sock.discard method simply makes your socket forget about the
connection- the other side is not notified at all.
345
7
279
343
292
328
348
331