Original Author Paul Laughton, 2011
Page 124
De Re BASIC!
The optional "wait" parameter determines if the command waits until a connection is made with a
client. If the parameter is absent or true (non-zero), the command waits for the connection. If the
parameter is false (zero), the command completes immediately. Use Socket.server.status to determine
when the connection is made.
In general, it is safer to set the parameter to false (don't wait) and explicitly monitor the connection's
status, since it can avoid a problem if the program exits with no connection made. You must use the
Socket.server.close command to stop a connection attempt that has not completed.
Socket.server.status <status_nvar>
Get the current server socket connection status and place the value in the numeric variable
<status_nvar>.
- 1 = Server socket not created
0 = Nothing going on
1 = Listening
3 = Connected
Socket.server.read.line <svar>
Read a line sent from the previously-connected Client and place the line into the string variable <svar>.
The command does not return until the Client sends a line. To avoid an infinite delay waiting for the
Client to send a line, the Socket.server.read.ready command can be repeatedly executed with timeouts.
Socket.server.read.ready <nvar>
If the previously-connected Client socket has not sent a line for reading by Socket.server.read.line then
set the return variable <nvar> to zero. Otherwise return a non-zero value.
The Socket.server.read.line command does not return until a line has been received from the Client.
This command can be used to allow your program to time out if a line has not been received within a
pre-determined time span. You can be sure that Socket.server.read.line will return with a line of data if
returns a non-zero value.
Socket.server.write.line <line_sexp>
Send the string expression <line_sexp> to the previously-connected Client as UTF-16 characters. End of
line characters will be added to the end of the line.
Socket.server.write.bytes <sexp>
Send the string expression, <sexp>, to the previously-connected Client as 8-bit bytes. Each character of
the string is sent as a single byte. The string is not encoded. No end of line characters are added by
BASIC!. If you need a CR or LF character, you must make it part of the string. Note that if
Socket.client.read.line is used to receive these bytes, the read.line command will not return until it
receives a LF (10, 0x0A) character.