[BIGTREETECH CB1 core board & PI4B trial] Chapter 8 UDP test
[Copy link]
UDP is a connectionless, insecure, message-based transport layer protocol. The communication process of UDP is also blocked by default.
- UDP communication does not require a connection to be established, so the connect() operation is not required.
- During UDP communication, you need to specify the IP and port of the data receiving end each time, which is similar to sending express delivery.
- UDP does not sort the received data, and there is no information about the data order in the header of the UDP message.
- UDP does not reply with confirmation information for the received datagram. The sender does not know whether the data is received correctly and will not resend the data.
- If data is lost, half of the data will not be lost. If the current data packet is lost, all of it will be lost.
Check out the PYTHON network programming book and quote this paragraph
The routine is mainly used to create a udp client
The server uses a network test tool running on a PC
The host's IP address is 192.168.43.13 and the port is configured the same
import socket
def main():
# udp communication address, IP+port number
udp_addr = ('192.168.43.13', 7878)
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Send data to the specified IP and port, send once every 1s, and send 10 times
for i in range(10):
udp_socket.sendto(("Hello,I am a UDP socket for: " + str(i)) .encode('utf-8'), udp_addr)
print("send %d message" % i)
sleep(1)
# 5. Close the socket
udp_socket.close()
if __name__ == '__main__':
main()
Copy the py file to the test folder of the development board
Cd test starts running the UDP client program
The test is as follows:
The client sends data to the server, and the server receives the relevant data
|