Original Author Paul Laughton, 2011
Page 121
De Re BASIC!
<result_svar> is where the Post response will be placed.
TCP/IP Sockets
TCP/IP Sockets provide for the transfer of information from one point on the Internet to another. There
are two genders of TCP/IP Sockets: Servers and Clients. Clients must talk to Servers. Servers must talk to
Clients. Clients cannot talk to Clients. Servers cannot talk to Servers.
Every Client and Server pair have an agreed-upon protocol. This protocol determines who speaks first
and the meaning and sequence of the messages that flow between them.
Most people who use a TCP/IP Socket will use a Client Socket to exchange messages with an existing
Server with a predefined protocol. One simple example of this is the Sample Program file,
f31_socket_time.bas. This program uses a TCP/IP client socket to get the current time from one of the
many time servers in the USA.
A TCP/IP Server can be set up in BASIC!; however, there are difficulties. The capabilities of individual
wireless networks vary. Some wireless networks allow servers. Most do not. Servers can usually be run
on WiFi or Ethernet Local Area Networks (LAN).
If you want to set up a Server, the way most likely to work is to establish the Server inside a LAN. You
will need to provide Port tunneling (forwarding) from the LAN's external Internal IP to the device's LAN
IP. You must to be able to program (setup) the LAN router in order to do this.
Clients, whether running inside the Server's LAN or from the Internet, should connect to the LAN's
external IP address using the pre-established, tunneled Port. This external or WAN IP can be found
using:
This is not the same IP that would be obtained by executing Socket.myIP on the server device.
Note: The specified IPs do not have to be in the numeric form. They can be in the name form.
The Sample Program, f32_tcp_ip_sockets.bas, demonstrates the socket commands for a Server working
in conjunction with a Client. You will need two Android devices to run this program.
TCP/IP Client Socket Commands
Socket.client.connect <server_sexp>, <port_nexp> { , <wait_lexp> }
Create a Client TCP/IP socket and attempt to connect to the Server whose Host Name or IP Address is
specified by the Server string expression using the Port specified by Port numeric expression.
The optional "wait" parameter determines if this command waits until a connection is made with the
Server. If the parameter is absent or true (non-zero), the command will not return until the connection