当前位置:网站首页>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 ...
边栏推荐
- Analyzing mobx responsive refresh mechanism from source code
- 面试题总结
- Title 68: there are n integers, so that the previous numbers are moved backward m positions, and the last m numbers become the first m numbers
- Vue —— 进阶 vue-router 路由(二)(replace属性、编程式路由导航、缓存路由组件、路由的专属钩子)
- MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column
- JS get the start and end dates of this week according to the nth week of the N year
- MySQL - > > symbol usage JSON related
- Title 66: input 3 numbers a, B, C, and output them in order of size.
- 用grep awk提取字符串
- VirtualLab basic experiment tutorial -4 Single slit diffraction
猜你喜欢

Write a select based concurrent server

OpenGL shadow implementation (soft shadow)

How to modify the authorization of sina Weibo for other applications

收获满满的下午

Review of MySQL (VI): usage of Union and limit

JS sum of two numbers

Title 68: there are n integers, so that the previous numbers are moved backward m positions, and the last m numbers become the first m numbers

MySQL - > > symbol usage JSON related

MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column

General differences between SQL server versions released by Microsoft in different periods so far, for reference
随机推荐
Summary of static memory allocation and dynamic memory allocation
CVPR 2022 Oral 大连理工提出SCI:快速、超强的低光照图像增强方法
2022.6.12 - leetcode. 89.
Leetcode topic [string] -151- flip words in string
Redis(三十二)-用Redis做分布式锁
即时配送的订单分配策略:从建模和优化-笔记
Solution to the problem that the anaconda navigator card logo cannot be opened and the card will flash back - replace the alicloud image source
Shenzhen has been shut down for 7 days since March 14. Home office experience | community essay solicitation
Review of MySQL (V): Joint table query and sub query
Gospel of audio and video developers, rapid integration of AI dubbing capability
Stack in JS (including leetcode examples) < continuous update ~>
Virtual Lab Basic Experiment tutoriel - 4. Diffraction à fente unique
Lenovo responded that there are too many and too messy notebooks: it is now the product adjustment period and will be divided into three series of digital /air/ pro in the future
Pytest automated testing framework (II)
SCI Writing - Results
279. perfect square
在思科模擬器Cisco Packet Tracer實現自反ACL
Go init initialization function
Leetcode topic [string]-541- reverse string II
JS for Fibonacci sequence