314
Platforms
©2000-2008 Tibbo Technology Inc.
Your inband reply will only be stored into the RPL buffer if the latter has enough
space to store your entire message. If there is not enough free space then nothing
will be stored. This is different from the TX buffer, for which whatever can fit is
stored. You can check the free space in the RPL buffer by using the
property. Amount of unsent data in the RPL buffer can be checked through the
property.
You must not split your inband reply- it must be placed in the RPL buffer with a
single invocation of sock.setsendinband. In the example below we reply back "OK"
to each inband command we receive:
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
'reply back with OK
sock.setsendinband(chr(sock.e
" OK"
+chr(sock.endchar))
'any more inband commands to process now?
x=instr(
1
,s,chr(sock.endchar))
wend
end
sub
And this would be an incorrect way- do not split inband replies!
...
sock.setsendinband(chr(sock.escchar))
'WRONG!
sock.setsendinband(
" OK"
)
'WRONG!
sock.setsendinband(chr(sock.endchar))
'WRONG!
...
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.
Notice how we have created a character after the escape character- by
adding a space in front of our "OK" reply, like this: " OK". This will
work fine as long as our escape character is not space!
Using HTTP
The sock object can function as a HTTP server. This means that when certain
conditions are met, individual sockets will switch into the HTTP mode and output
the data in a style, consistent with the HTTP server functionality.
Certain BASIC information about the HTTP server has already been provided in
and
Embedding Code Within an HTML File
.
When the socket is in the HTTP mode your program has no control over the
received data (HTTP requests) and only sometimes has control over the
350
350
74
76