User guide

20
We developed a simple communication protocol used between the client on Palm and the
server for uploading data. The server runs on a Unix host. It uses port number 7002,
which should be available. If it is not, the port number can be easily changed.
The figure on the previous page shows the data flow from Palm client to the server, and a
sample graph as it appears on the web page.
Functions
We developed a collection of generic functions for basic TCP/IP communications.
static int make_connection(char *service, int type, char
*netaddress)
/* This is a generic function to make a connection to a given server/port.
service is the port name/number,
type is either SOCK_STREAM or SOCK_DGRAM, and
netaddress is the host name to connect to.
The function returns the socket, ready for action.*/
static int atoport(char *service, char *proto)
/* Take a service name, and a service type, and return a port number. The number
returned is byte ordered for the network. */
static struct in_addr *atoaddr(char *address)
/* Converts ascii text to in_addr struct. NULL is returned if the address can not be
found. */
static int sock_gets(int sockfd, char *str, size_t count)
/* This function reads from a socket, until it receives a linefeed character. It fills the
buffer "str" up to the maximum size "count". This function will return -1 if the socket
is closed during the read operation.If a single line exceeds the length of count, the
extra data will be read and discarded */
static int sock_puts(int fd, char *body)
/* This function writes to a socket all the newline-terminated lines contained in body.
This function will return -1 if the socket is closed during the write operation.*/
Using the above functions, we developed two more complex functions, which are also
very general: sendmail() and senddata(). In order to maintain the generality of these