300
Platforms
©2000-2008 Tibbo Technology Inc.
Keep in mind that there is a limitation for the maximum length of data in the UDP
datagram- 1536 bytes.
Receiving Data
Receiving data in UDP mode requires you to be within an event handler for
incoming socket data, or to explicitly move to the next UDP datagram in the buffer.
To extract the data from a buffer, use the
method. This method
only accesses a single datagram on the buffer, unless you use the
method. If you have several incoming datagrams waiting, you will have to
process them one by one, moving from one to the next. This is good because this
way you know where one datagram ends and another one begins.
Here is an example:
sub
on_sock_data_arrival
dim
whatigot
as
string
whatigot = sock.getdata(
255
)
'will only extract the contents of a
single datagram. Reenter the on_sock_data_arrival to get the next datagram
end
sub
Data may only be extracted once from a buffer. Once extracted, it is no longer in
the buffer. Discussion of UDP data RXing continues in
.
TX and RX Buffer Memory Status
You cannot effectively use a buffer without knowing what is its status. Is it
overflowing? Can you add more data? etc. Thus, each of the socket buffers has
certain properties which allow you to monitor it:
The RX buffer
You can check the total capacity of the buffer with the
property.
You can also find out how much data the RX buffer currently contains with the
property. From these two data, you can easily deduce how much free
space you have in the RX buffer -- even though this isn't such a useful datum
(that's one of the reasons there is no explicit property for it).
Note that sock.rxlen returns the gross current size of data in the RX buffer. In TCP
mode, this is equivalent to the actual amount of data in the buffer. However, in
UDP mode, this value includes the headers preceding each datagram within the RX
buffer -- the amount of actual data in the buffer is smaller than that. A separate
property --
returns the length of actual data in the UDP
datagram you are currently processing.
Sometimes you need to clear the RX buffer without actually extracting the data. In
such cases the
comes in handy.
The TX buffer
Similarly to the RX buffer, the TX buffer also has a
property
which lets you discover its capacity.
The TX buffer has two "data length" properties:
and
. The txlen property returns the amount of committed data waiting to be sent from
the buffer (you commit the data by using the
method). The newtxlen
property returns the amount of data which has entered the buffer, but has not yet
333
339
303
351
352
352
351
363
364
339
353