Sample TCP/IP Communication Programs
On the following pages are four pieces of sample code written in Berkeley Sockets as an example of the type of custom code which must be written so that the Serial Adapter can communicate with nodes on an Ethernet network.
Note:
If your custom program makes use of the “$QUIT” command so that the Serial Adapter will close open TCP connections, set the TCP Close Connection Signal pa- rameter to “Yes” within the Serial Adapter’s Advanced Configuration Menu.
Sample TCP Receive Program
1/*******************************************************
2* tcprecv.c
3* Receives messages from one or more Serial Adapters using TCP
4*
5*******************************************************/
7#include <sys/types.h>
8#include <sys/socket.h>
9#include <netinet/in.h>
10#include <netdb.h>
11#include <stdio.h>
13#define TRUE 1
15main()
16{
17int i, sock, length;
18struct sockaddr_in server;
19int msgsock;
20char buf[1024];
21int rval;
22FILE *logfile;
91