305
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
dim
s
as
string
s =
"This is a long string waiting to be sent. Send me already!"
sub
on_button_pressed
sock.notifysent(sock.txbuffsize-len(s))
' causes the
on_sock_data_sent event to fire when the TX buffer has space for our
string
end
sub
sub
on_sock_data_sent
sock.setdata(s)
' put data in TX buffer
sock.send
' start sending it.
end
sub
When we press the button,
event is generated, so now the
system knows we have a string to send. Using
we make the
system fire the on_ser_data_sent event when the necessary amount of free space
becomes available. This event will only be fired once -- and will be fired
immediately if there is already enough available space.
Within the event handler for this event, we put the data in the TX buffer and start
sending it.
Amount of data that will trigger on_sock_data_sent does not include
uncommitted data in the TX buffer.
UDP datagrams are generated as you create them
we have already explained that for UDP you have
a complete control over how the data you are sending is divided into the UDP
datagrams. Each time you use the sock.send method you draw the boundary
between the datagrams- the previous one is "closed" and the new one "begins".
You can even send out an empty UDP datagram by executing
without
using the
first.
Correctly responding to the sender of each UDP datagram
With UDP, your socket may be receiving UDP datagrams from several different
hosts. When the on_sock_data_arrival event handler is entered (see
) the following properties automatically reflect the source of
,
property will tell you whether the datagram
was a regular or a broadcast one (this material has already been covered in
).
Additionally, any datagram that was generated and sent from within the
on_sock_data_arrival event handler will be send to the sender of the datagram for
processing of which the on_sock_data_arrival event handler was entered.
The point is that if you are sending out a datagram from within the
on_sock_data_arrival event handler you are automatically replying to the sender of
the datagram being processed. The following example sends back "GOT
DATAGRAM FROM xxx.xxx.xxx.xxx" string in response to any datagram received by
the socket:
273
340
299
353
353
303
348
347
348
328
292