297
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
'Even better code!
...
...
sock.close
While
sock.statesimple<>PL_SSTS_CLOSED
'here we wait for the connection
to be closed
doevents
'Not necessary but useful -- lets other events execute
Wend
doevents
' Absolutely essential for this particular case!
sock.connect
...
You have to place doevents after the while-wend loop and you have to
do this even if you don't actually have a handler for the
event in your application!
Sending and Receiving data
Once a network connection has been established the socket is ready to send and
receive the data. This is done through two buffers- the TX buffer and the RX buffer.
Read on and you will know how to allocate memory for buffers, use them, handle
overruns, and perform other tasks related to sending and receiving of data.
Allocating Memory for Buffers
Each buffer has a certain size, i.e, a memory capacity. This capacity is allocated
upon request from your program. When the device initially boots, no memory is
allocated to buffers at all.
Memory for buffers is allocated in pages. A page is 256 bytes of memory.
Allocating memory for a buffer is a two-step process: first you have to request for
a specific allocation (a number of pages) and then you have to perform the actual
allocation.
For the socket object to be able to send and receive the data, you have to give its
TX and RX buffers some memory. This is done through the
and
methods.
The allocation method (
) applies to all buffers previously specified,
in one fell swoop.
Hence:
dim
in, out
as
byte
out = sock.txbuffrq(
10
)
' Requesting 10 pages for the TX buffer. Out will
then contain how many can actually be allocated.
in = sock.rxbuffrq(
7
)
' Requesting 7 pages for the RX buffer. Will return
number of pages which can actually be allocated.
' ... Allocation requests for other buffers...
sys.buffalloc
' Performs actual memory allocation, as per previous
requests.
Actual memory allocation takes up to 100ms, so it is usually done just once, on
boot, for all required buffers. If you do not require some buffer, you may choose
not to allocate any memory to it. In effect, it will be disabled.
343
362
350
217