当前位置:网站首页>232-ch579m learning and development Ethernet routine TCP server (project application package, LAN or WAN test)
232-ch579m learning and development Ethernet routine TCP server (project application package, LAN or WAN test)
2022-06-12 18:39:00 【Yangfengwu】
explain
This section demonstrates that the development board acts as TCP Server and upper computer TCP Client LAN communication
Prepare a router or switch .
test
1. A router or switch connected by a network cable ( Connect to the same computer )
2. Compile and download the program in this section to the development board
3. The serial port on the development board will print the IP Address
4. Turn on the computer TCP Debugging assistant ( Install the following , Can test multiple channels TCP client )
5. Create connection
IP Fill in the address of the development board IP Address , This should be filled in according to the serial port printed above , My is 192.168.1.101
Development board TCP The port number that the server listens on is 6666
6. The development board will print the connected client information
TCP The debugging assistant will receive data from the development board at regular intervals
7. The computer debugging assistant sends data to the development board (TCP The server )
Development board (TCP The server ) Reply to whatever data you receive , At the same time, it will use the serial port to output the received information ,
8. Create another client to connect
The second client receives data from the server at regular intervals , Others will not be tested
Program description
1, The program is encapsulated , Let me explain how to use
2, To build a TCP Server variables
net_tcp_server_struct net_tcp_server;
3, hold net_tcp_server_data Function is put into the network event handler
4, Set the port number that the server listens to
5, Because it's a LAN , So in DHCP The callback function calls TCP Server creation function
The following callback function is written in this way , I will explain the processing procedure later ( The example I provided supports multiple connections , So there are a lot of programs )
6, After the client is connected, it will enter this
Because the actual project may need to send messages to the client elsewhere , So record this socket
It's written below if Judgment is to judge which variable is not used , Just use which variable to record
If there is only one client, you can
7, Receive messages from clients
You can also know the information of the client in the receiving ip Address and port number
printf("ip address:%d,%d,%d,%d,%ld\r\n",
SocketInf[socket_client_value->socket_id].IPAddr[0],
SocketInf[socket_client_value->socket_id].IPAddr[1],
SocketInf[socket_client_value->socket_id].IPAddr[2],
SocketInf[socket_client_value->socket_id].IPAddr[3],
SocketInf[socket_client_value->socket_id].DesPort
);8, Send a message to the client
The direct return in the receive is written as follows
Sending data to the client elsewhere requires the previous variable
matters needing attention
1, In case of multiple client connections , actually socket1,socket2,socket3,socket4 The record of variables may be variable .
Suppose there is 2 A client , 192.168.1.90 ; 192.168.1.101
In limine 192.168.1.90 Connect first 192.168.1.101 Back connection ,
Now? socket1 Recorded 192.168.1.90; socket2 Recorded 192.168.101
But if two clients are disconnected and connected repeatedly from time to time , The record may change
Probably socket2 Record 192.168.90 ; socket1 Record 192.168.1.101
I'll come back and write ...
边栏推荐
- Remote gadget putty (Alibaba cloud mirror station address sharing)
- Random talk about redis source code 91
- General differences between SQL server versions released by Microsoft in different periods so far, for reference
- Adjust CEPH cluster image source
- Go init initialization function
- 论大型政策性银行贷后,如何数字化转型 ?-亿信华辰
- Vue —— 进阶 vue-router 路由(二)(replace属性、编程式路由导航、缓存路由组件、路由的专属钩子)
- lua记录
- MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column
- MySQL advanced learning notes
猜你喜欢

快速复制浏览器F12中的请求到Postman/或者生成相关语言的对应代码
![Interior design style type, rendering 100 invitation code [1a12]](/img/90/8bbfbe33c5b412498744c0ea0ed559.jpg)
Interior design style type, rendering 100 invitation code [1a12]

Write a select based concurrent server

HTTP cache < strong cache and negotiation cache >

C语言练习(4)——大数乘除

Difference between rxjs of() and of ({})

GD32F4xx控制DGUS触控按键

Pytest automated testing framework (II)

Partial scratch and corrosion detection of bolts and screws based on Halcon

Go init initialization function
随机推荐
torch. New usage of where (old but ignored usage)
配送交付时间轻量级预估实践-笔记
C语言学习——数据在内存中的存储
"Big fat • small lesson" - talk about big file segmentation and breakpoint sequel
GD32F4xx控制DGUS触控按键
Leetcode topic [string]-541- reverse string II
从应无所住说起
In 2021, the global spice and seasoning revenue is about 18720million US dollars, and it is expected to reach 25960million US dollars in 2028
JS moves the 0 in the array to the end
bilibili视频列表名字太长显示不全的解决方法
C language operation database (SQLite3) call interface function
在思科模擬器Cisco Packet Tracer實現自反ACL
Changes in the third generation dri
Strings in JS (including leetcode examples) < continuous update ~>
在思科模拟器Cisco Packet Tracer实现自反ACL
Redis(三十二)-用Redis做分布式锁
Stack in JS (including leetcode examples) < continuous update ~>
Random talk about redis source code 90
Free measurement of rectangular card [manual drawing ROI] Based on Halcon
笔记本电脑清灰打硅脂后,开机一直黑屏,如何破?