SIMPOL Documentation

Sample TCP/IP Server and Client Programs

Two sample programs are shipped with SIMPOL. They can be found in the \SIMPOL\Projects\sockets directory. One is called clientsample and the other is serversample. Together they implement a very rudimentary file transfer system that could fairly easily be built into a live update type of mechanism.

They each contain a receivestring() function that was taken directly from a commercial application built in-house. This particular function design requires that the other end respond with a carriage-return linefeed pair or a linefeed alone (should work fine on Windows, Linux, and OS-X). The function was designed so that it can also work together with directly typed input, such as from Telnet. The server simply sits there doing nothing until a connection is made. At that point a new thread is spawned and passed to the dispatch() function, along with the incoming socket object.

Within the dispatch() function a HELO is sent to identify the server as a response to the connection. A loop is entered to process the commands supported by the server. If nothing arrives within a specific amount of time, then the loop will time out and the connection will be closed. The client receives the HELO and then requests the time by sending the TIME command. After receiving the time from the server, it sends the GET command and the server responds by opening and then transmitting its own program file, prefaced with a minimal header to tell the client the amount of data being sent. The client receives the data using the receiveblob() function and stores it. It then sends the QUIT command to allow the server to exit the loop immediately rather than waiting for a time out.