301
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
been committed for sending. For UDP, this is basically the length of UDP datagram
being created.
property, which directly tells you how much
space is left in it. This does not take into account uncommitted data in the buffer --
actual free space is sock.txfree-sock.newtxlen!
ser.txlen + ser.txfree = ser.txbuffsize.
When you want to clear the TX buffer without sending anything, use the
method. Notice, however, that this will only work when the network
connection is closed (
= PL_SSTS_CLOSED).
An example illustrating the difference between sock.txlen and sock.newtxlen:
sub
on_sys_init
dim
x,y
as
word
' declare variables
sock.rxbuffrq(
1
)
' Request one page for the RX buffer.
sock.txbuffrq(
5
)
' Request 5 pages for the TX buffer (which we will use).
sys.buffalloc
' Actually allocate the buffers.
sock.setdata(
"foofoo"
)
' Set some data to send.
sock.setdata(
"bar"
)
' Some more data to send.
sock.send
' Start sending the data (commit).
sock.setdata(
"baz"
)
' Some more data to send.
x = sock.txlen
' Check total amount of data in the TX buffer.
y = sock.newtxlen
' Check length of data not yet committed.
end
sub
'Set up a breakpoint HERE.
Don't step through the code. The sending is fast -- by the time you reach x and y
by stepping one line at a time, the buffer will be empty and x and y will be 0. Set a
breakpoint at the end of the code, and then check the values for the variables (by
using the
).
Receiving Data in TCP Mode
We have already explained that RX and TX buffers operate differently in the
and
mode. This section explains how to receive data when the TCP protocol
is used by the socket.
In a typical system, there is a constant need to handle an inflow of data. A simple
approach is to use polling. You just poll the buffer in a loop and see if it contains
any fresh data, and when fresh data is available, you do something with it. This
would look like this:
sub
on_sys_init
while
sock.rxlen =
0
wend
' basically keeps executing again and again as long as sock.rxlen = 0
s = sock.getdata(
255
)
' once loop is exited, it means data has arrived. We
extract it.
end
sub
This approach will work, but it will forever keep you in a specific event handler
363
363
358
33
298
299