- Proxima RangeLAN2 Serial Adapter User's Guide

91
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 *******************************************************/
6
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <netdb.h>
11 #include <stdio.h>
12
13 #define TRUE 1
14
15 main()
16 {
17 int i, sock, length;
18 struct sockaddr_in server;
19 int msgsock;
20 char buf[1024];
21 int rval;
22 FILE *logfile;