USR-TCP232-302 User Manual
h.usriot.com
Jinan USR IOT Technology Limited
50 / 53
72.
ptr += retlen;
73.
}
74.
//receive data
75.
recvlen = 0;
76.
retlen = 0;
77.
ptr = recvbuf;
78.
leftlen = RECV_BUF_SIZE -1;
79.
//do
80.
{
81.
retlen = recv(app_sock, ptr, leftlen, 0) ;
82.
if(retlen < 0)
83.
{
84.
if(errno == EINTR)
85.
retlen = 0;
86.
else
87.
exit(1);
88.
}
89.
r= retlen;
90.
leftlen -= retlen;
91.
ptr += retlen;
92.
}
93.
//while(recvlen && leftlen);
94.
printf("receive data is : %s", recvbuf);
95.
close(app_sock);
96.
}
97.
close(listen_sock);
98.
99.
return 0;
100.
}
Client Socket code:
1.
#include <stdio.h>
2.
#include <string.h>
3.
#include <sys/socket.h>
4.
#include <netinet/in.h>
5.
#include <syslog.h>
6.
#include <errno.h>
7.
#include <stdlib.h>
8.
#define MAX_LISTEN_NUM 5
9.
#define SEND_BUF_SIZE 100
10. #define RECV_BUF_SIZE 100
11. #define SERVER_PORT 1010
12. int main()
13. {
int sock_fd = 0;