EasyManua.ls Logo

USR IOT USR-TCP232-302 - Upper computer Socket programming example

USR IOT USR-TCP232-302
53 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
USR-TCP232-302 User Manual h.usriot.com
Jinan USR IOT Technology Limited www.usriot.com
48
/ 53
Appendix:ID type of Independent ID
This byte is the last byte of 3 bytes, additional meaning is as follows:
bit0(1) send ID when connecting;
bit1(2)send ID when send data;
bit2(4) RS485;
bit3(8) NC;
bit4(16) Reset;
bit5(32) Link-state;
bit6(64) tcp server index;
bit7(128) baud rate synchronization, similar RFC2217.
When each bit is 1, it means related function is invalid. Otherwise, it is valid, default is
RS485 and similar RFC2217 set 1 .(turn on function, value is 0x84 )
Appendix :Upper computer Socket programming example
Server Socket code:
1. #include <stdio.h>
2. #include <string.h>
3. #include <sys/socket.h>
4. #include <netinet/in.h>
5. #include <stdlib.h>
6. #include <syslog.h>
7. #include <errno.h>
8. #define MAX_LISTEN_NUM 5
9. #define SEND_BUF_SIZE 100
10. #define RECV_BUF_SIZE 100
11. #define LISTEN_PORT 1010
12. int main()
13. {
14. int listen_sock = 0;
15. int app_sock = 0;
16. struct sockaddr_in hostaddr;
17. struct sockaddr_in clientaddr;
18. int socklen = sizeof(clientaddr);
19. char sendbuf[SEND_BUF_SIZE] = {0};
20. char recvbuf[RECV_BUF_SIZE] = {0};
21. int sendlen = 0;
22. int recvlen = 0;
23. int retlen = 0;
24. int leftlen = 0;
25. char *ptr = NULL;
26. memset((void *)&hostaddr, 0, sizeof(hostaddr));

Table of Contents

Related product manuals