Omron CS1W-ETN21 Network Card User Manual


 
168
FINS/UDP Method Section 7-3
Sample Program
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_UDP_PORT 9600
9#define SERV_IP_ADDR "196.36.32.100" /* Ethernet Unit IP ADDRESS*/
10#define MAX_MSG 2010
11#define RESP_TIMEOUT 2
12
13
14/*
15* FINS/UDP COMMUNICATIONS SAMPLE PROGRAM
16*/
17main(argc,argv)
18int argc;
19char *argv[];
20{
21 int sockfd;
22 struct sockaddr_in ws_addr, cs_addr;
23 char fins_cmnd[MAX_MSG], fins_resp[MAX_MSG];
24 int sendlen, recvlen, addrlen;
25 char sid = 0;
26 extern recv_fail();
27
28 /*
GENERATE UDP SOCKET*/
29 if ((sockfd = socket(AF_INET,SOCK_DGRAM,0)) < 0)
30 err_exit("can't open datagram socket");
31