277
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
sock.num =
0
sock.protocol =
1
sock.connectiontimeout =
10
sock.httpmode =
1
' etc
The events for this object are not separate for each socket. An event such as
serves all sockets on your platform. Thus, when an event
handler for the socket object is entered, the socket selector is automatically
switched to the socket number on which the event occurred:
sub
on_sock_data_arrival
dim
s
as
string
s = sock.getdata(
255
)
' Note that you did not have to specify any
sock.num preceding this statement.
end
sub
As a result of this automatic switching, when an event handler for a socket event
terminates, the sock.num property retains its new value (nothing changes it back).
You must take this into account when processing other event handlers which make
use of a socket (and are not socket events). In other words, you should explicitly
set the sock.num property whenever entering such an event handler, because the
property might have been automatically changed prior to this event. To illustrate:
sub
on_sys_init
' This is always the first event executed.
sock.num =
0
' Supposedly, this would make all subsequent
properties and methods refer to this socket.
end
sub
sub
on_sock_data_arrival
' Then, supposing this event executes.
dim
s
as
string
s = sock.getdata(
255
)
' However, this event happens on the second
socket. So now sock.num = 1.
end
sub
sub
on_ser_data_arrival
' And then this serial port event executes.
sock.txclear
' You meant to do this for sock.num = 0 (as specified
at on_sys_init). But now sock.num was changed to 1! Oops...
end
sub
To recap, only one of two things may change the current sock.num: (1) manual
change or (2) a socket event. You cannot assume the number has remained
unchanged if you set it somewhere else (because a socket event might have
happened since).
Handling Network Connections
The whole purpose of socket's existence is to engage in network connections with
other network hosts. Each socket can maintain a single connection using a UDP/IP
or TCP/IP transport protocol. Which of the two is used is defined by the
property.
Sockets are also capable of working with HTTP. HTTP is not a transport protocol,
rather, it is based on the TCP. Therefore, when your socket is using TCP it may be
for "plain data transmission" or for HTTP.
342
345