306
Platforms
©2000-2008 Tibbo Technology Inc.
sub
on_sock_data_arrival
sock.setdata(
"GOT DATAGRAM FROM "
+ sock.remoteip)
sock.send
end
sub
For the above example, even if several hosts send the datagrams to the socket at
the same time each one of these hosts will get a correct reply back!
Now consider this example: each time the button is pressed the same message is
generated:
sub
on_button_pressed
sock.setdata(
"GOT DATAGRAM FROM "
+ sock.remoteip)
sock.send
end
sub
The difference is that when you press the button the datagram will be sent to the
destination, from which the most recent incoming UDP datagram was received
(and accepted) by the socket!
"Split Packet" Mode of TCP Data Processing
Though our customer's feedback we have learned that sometimes it may be
necessary to know the size of individual TCP packets. For example, as it turns out,
some data encryption methods work on a packet level. Erase the border between
TCP packets -- and you can't decrypt the data.
Introduced in Tibbo Basic V2.0, new
property and
event allow you to process incoming TCP data
packet by packet. To achieve this, set the sock.splittcppacket= 1- YES. After that,
the on_sock_tcp_packet_arrival will be generated for each incoming TCP packet
carrying any new data (i.e., not a retransmission data). Here is an example of use:
dim
rx_tcp_packet_len
as
word
'to keep the size of the next incoming TCP
packet
sub
on_sys_init
...
rx_tcp_packet_len=0
sock.splittcppackets=YES
end
sub
sub
on_sock_tcp_packet_arrival(len
as
word
)
rx_tcp_packet_len=len
'we get the size of the next packet we are going
to process
end
sub
sub
on_sock_data_arrival
dim
s
as
string
'take exactly the contents of one packet (we assume that it can fit in
the string!)
s=sock.getdata(rx_tcp_packet_len)
rx_tcp_packet_len=0
'very important!
end
sub
Naturally, you may also need to control the size of outgoing TCP packets. This is
done in a different way. With
= 1- YES, when you put some
355
344
355