Network programming: UDP
to understand network programming, you first need to understand what a network is (understand):
Network definition: The network refers to the independent function of multiple computers through the communication line, in the network management software and network communication protocol, the realization of resource sharing and information transmission virtual platform.
Popular can be understood as: is the two or more devices connected together a tool, and then can be transmitted data.
# 1, IP address:
An IP address is like a home address, where you can send a message by locating the only device in the network via an IP address. (Addresses are IPv4 and IPv6)
Locate the only device in the network with an IP address, and then send the data to the device.
Private IP (understanding):
The private IP is the IP address used in the LAN, and some IP addresses are used in the local area network:
Native IP address:
127.0.0.1 represents the native IP address; The native domain name is localhost; Through the domain name can be resolved an IP address, domain name convenient for everyone to remember the host address of a computer
2,ifconfig (ipconfig) To view the native IP in the terminal.
3, Ping can check whether the network is normal
(1). ping 127.0.0.1 Check if the local network adapter is healthy
(2). Ping www.baidu.com Check if you can get on the public network
(3). Ping the IP address of the current local area network check if it is within the same LAN
A port is a channel that transmits data, like a classroom door.
5, port number:
Using a unique number to identify the port is actually a number for the port, such as qq4000
well-known port number (understanding):
The well-known port number is a well-known port number, ranging from 0 to 1023, which can be understood as the number used for some commonly used functions is estimated, like phone numbers 110, 10086, 100,101
Dynamic port number (Learn):
A programmer develops an application that uses a port number, which is called a dynamic port because it is generally not assigned a service, but is dynamically allocated, and the port range is from 1024 to 65535. When the program shuts down, it also frees the port number that is occupied.
5. View port number:
Use Netstat-an to view the port number used by the program
Lsof-i [tcp/udp]:2425 View the application for the port number
Tip: If the port number cannot be found for the application, use Administrator privileges plus sudo
After you find the application for the port number, you can use the kill-9 number if you want to end the process. Kill process
6, the flow of network communication:
The process of network communication is to find the device in the network through the IP address, then find the corresponding port by the port number, then transmit the data to the corresponding application via the ports.
Network transmission mode UDP:
UDP: English full spell (user Datagram Protocol) referred to as Subscriber Datagram Protocol, it is a non-connected, unreliable network transport protocol
1, UDP Features:
Low resource overhead
Fast transmission speed
UDP maximum per packet is 64K
2, UDP disadvantage:
Unreliable transmission data, easy packet loss
No traffic control, when the other party does not receive data in a timely manner, the sender has been sending data will cause the buffer data is full, the computer is stuck, all receivers need to receive data in time
UDP is a simple transport-layer protocol for datagrams. UDP does not provide reliability, it simply sends the application to the IP layer's datagram, but does not guarantee that it will reach its destination. Because UDP does not have to establish a connection between the client and the server before transmitting the datagram, and there is no mechanism such as time-out retransmission, the transmission speed is very fast.
Python Network Programming Fundamentals-Basic knowledge of the network and the basic introduction of the transmission mode UDP