background image
Original Author Paul Laughton, 2011
Page 123
De Re BASIC!
Socket.client.write.bytes <sexp>
Send the string expression, <sexp>, to the previously-connected Server 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.server.read.line is used to receive these bytes, the read.line command will not return until it
receives a LF (10, 0x0A) character.
Socket.client.write.file <file_nexp>
Transmit a file to the Server. The <file_nexp> is the file index of a file opened for read by Byte.open.
Example:
Byte.open r, fr, "image.jpg"
Socket.client.write.file fr
Byte.close fr
Socket.client.close
Closes an open client side connection.
TCP/IP Server Socket Commands
Socket.myIP <svar>
Returns the IP of the device in string variable <svar>. If the device has no active IP address, the returned
value is the empty string "".
If the device is on a WiFi or Ethernet LAN then the IP returned is the device's LAN IP.
Note: The external or WAN IP can be found using:
Graburl ip$, "
http://icanhazip.com
"
Socket.myIP <array$[]>{, <nvar>}
Returns all active IP addresses of the device in the string array <array$[]>. If you provide the optional
address-count variable <nvar>, it is set to the number of active IP addresses.
If the device has no active IP address, the array has a single element, the empty string "", and the
address-count in <nvar> is 0. In this case only, the address-count is not the same as the array length.
Most devices usually have zero or one IP address. It is possible to have more than one. For example,
after enabling a WiFi connection, there may still be an active cellular data connection. Normally this
connection shuts down after a short time, but in some cases it may remain open.
Socket.server.create <port_nexp>
Establish a Server that will listen to the Port specified by the numeric expression, <port_nexp>.
Socket.server.connect {<wait_lexp>}
Direct the previously created Server to accept a connection from the next client in the queue.