Omron CJ1W-ETN21 Network Card User Manual


 
186
FINS/TCP Method Section 7-4
Sample Program
/* Ethernet Unit IP ADDRESS*/
COMMUNICATIONS SAMPLE PROGRAM
GENERATE TCP SOCKET*/
1#include <errno.h>
2#include <stdio.h>
3#include <sys/types.h>
4#include <sys/socket.h>
5#include <netinet/in.h>
6#include <signal.h>
7
8#define FINS_TCP_PORT 9600
9#define SERV_IP_ADDR "196.36.32.100"
10#define MAX_MSG 2010
11#define MAX_HEADER 32
12#define RESP_TIMEOUT 2
13
14
15/*
16* FINS/TCP
17*/
18main(argc,argv)
19int argc;
20char *argv[];
21{
22 int sockfd;
23 struct sockaddr_in ws_addr, cs_addr;
24 unsigned char fins_cmnd[MAX_MSG], fins_resp[MAX_MSG], fins_tcp_header[MAX_HEADER];
25 unsigned char srv_node_no, cli_node_no;
26 int sendlen, recvlen;
27 char sid = 0;
28 extern recv_fail();
29
30 /*
31 if ((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0)
32 err_exit("can't open stream socket");