313
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
sub
on_sock_inband
dim
s
as
string
'we will keep the data from the CMD buffer here
dim
s2
as
string
'this will keep individual inband commands
dim
x
as
byte
s=sock.getinband
'we get entire CMD buffer contents into the s
x=instr(
1
,s,chr(sock.endchar))
while
x<>
0
s2=left(s,x-
1
)
's2 now contains a single inband command
s=right(s,len(s)-x)
'cut out this command
'process inband command in the s2 as needed
...
...
'any more inband commands to process now?
x=instr(
1
,s,chr(sock.endchar))
wend
end
sub
For the above example to work well, the size of the CMD buffer must
not exceed the capacity of string variable s. This way whatever is
extracted from the CMD buffer will always fit in s. A slightly more
complex processing is needed if the buffer is larger than the capacity of
s.
Are CMD buffer overruns possible?
CMD buffer overruns are not possible. If the socket receives an inband command
that cannot be saved into the CMD buffer in its entirety, then the socket will
discard the whole command (your program won't be notified of this in any way).
Therefore, you are guaranteed to always receive complete inband commands, or
nothing at all.
Incomplete inband commads
Take a look at this datastream:
Data@!comma@!command2&Moredata
What we have here is an inband command that is incomplete- a new inband
command starts before the previous one ends. Such incomplete commands are
discarded and not recorded into the CMD buffer.
Sending Inband Replies
How to generate inband reply correctly
Inband replies are sent from the RPL buffer. Unlike the process of sending
"regular" TX data that requires you to use
and
methods, the process of sending an inband reply only takes one step. You set and
send (commit) the data with a single method-
.
The sock.setsendinband method puts the data into the RPL buffer and immediately
commits it for sending. The socket does not add necessary incapsulation
automatically: it is the responsibility of your application to add the escape
character, some other character after the escape, and the end character.
353
353
354