299
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
Receiving data is a one-step process. To extract the data from the RX buffer, use
the
method. Data may only be extracted once from the buffer.
Once extracted, it is no longer in the buffer. For example:
dim
whatigot
as
string
whatigot = sock.getdata(
255
)
The string whatigot now contains up to 255 bytes of data which came from the RX
buffer of the socket.
Discussion of TCP data RXing continues in
.
Using Buffers in UDP Mode
UDP is a packet-based protocol (as opposed to TCP, which is stream-based). In
UDP you usually care what data belongs to what datagram (packet). The sockets
object gives you complete control over the individual datagrams you receive and
transmit.
Sending and receiving UDP data is still effected through the TX and RX buffers. The
difference is that the subdivision into datagrams is preserved within the buffers.
Each datagram in the buffer has its own header:
For the TX buffer, headers contain datagram length as well as the destination
MAC, IP, port, and broadcast flag (indicating whether to send the datagram as a
broadcast).
For the RX buffer, headers contain datagram length plus the sender's MAC, IP,
port, and broadcast flag (indicating whether the datagram is a broadcast).
Sending Data
Just like with TCP, sending data through the TX buffer in UDP mode is a two-step
process; first you put the data in the buffer using the
method, and
then you close a datagram and perform the actual sending (commit the data)
using the
method.
The datagrams will never be mixed with one another. Once you invoke sock.send,
the datagram is closed and sent (as soon as possible). Any new data added to the
TX buffer will belong to a new datagram. For example:
sock.setdata (
"Foo"
)
' Placed our data in the tx buffer - not being sent
out yet.
' ... more code...
sock.setdata (
"Bar"
)
' Added even more data to the same datagram, waiting
to be sent.
sock.send
' A datagram containing 'FooBar' will now be closed and
committed for sending.
sock.setdata (
"Baf"
)
' This new data will go into a new datagram.
sock.send
' Closes the datagram with only 'Baf' in it and commits it for
sending.
sock.send
' sends an empty UDP datagram!
Notice that in the example above we were able to send out an empty datagram by
using sock.send without sock.setdata!
333
301
353
353