Normally, the client and server should run on different
computers. For the moment, we are assuming both
computers are on the same LAN, but more on that shortly.
If you don’t have two computers available, you can start
two instances of RobotBASIC on the same computer and
run the server on one instance and the client on the other.
Figure 4 shows how the communication proceeds
when both programs are running on the same computer.
The smaller window segment is the server. Notice that
the messages typed into the client appear on the server’s
screen and the message Got It is received and displayed by
// Enter the Server’s IP and port below
rmtIP = “192.168.0.27”
rmtPort = 42001
n = tcpc_connect(rmtIP,rmtPort)
// wait for connect or error
t = timer()
while timer()-t < 5000
Status = tcpc_Status()
if left(Status,9) == “Connected” then break
if left(Status,5) == “Error” then break
if left(Status,9) = “Connected”
print “No server found”\end
Communicating Outside the LAN
The two programs discussed work fine if both
computers are on the same LAN (both connected to the
same router). If the two computers are on different LANs,
the process is slightly more complicated.
Inside your LAN, it’s easy to use each computer’s
// let user enter text to be sent
input “Enter message to be sent: “, sBuff
n = tcpc_Send(sBuff)
// wait for a reply and print it
x = tcpc_read() //clear buff
IP and port to establish the communication. If the two
computers are on different LANs though, you need to use
the IP address of the router controlling each LAN.
Actually, you only need the IP address of the server’s
router because the client’s IP address is automatically
embedded into the messages it sends. This lets the server
respond properly without you having to deal with the
The server program doesn’t have any way of
determining the address of your router, so you must
handle that manually. One easy way of doing that is to
use the webpage www.WhatIsMyIP.com.
When you access that page, you’ll see several pieces
of information. The only one you need is the IP address
labeled IPv4. It’s the address of the router to which your
computer is attached. This is the address you should type
into the client program (not the local IP for the server’s
return Figure 3.
66 SERVO 09/10.2018