Beginner python road -day33

1.udp agreement

UDP: User Datagram Protocol 
In the OSI model, the protocol belonging to the transport layer, 
is not reliable, simple and does not require packet transmission order and a smaller amount of data, the transmission speed 
is similar to walkie-talkies, simply transmit data, regardless of whether the other party to accept, or even do not care whether they're online 

the difference between the tcp: 
unreliable transport, without having to establish a connection, but will not stick package, but the data packets sent each time not too big 
addition is based on UDP datagram, every transmission is a single datagram, it will not stick package problem : when sending data 
udp send data Once sent, the data cache will be deleted, if the other party does not receive the data is gone, resulting in loss of data 
after sending data in tcp We will wait for confirmation, if the acknowledgment is not received, the data stored in the buffer will go until sent successfully or wait too long timeout Note: the data length of the sender shall be subject to uniform length with the recipient, or they will be lost data, error directly under windows.






  Buffer size can not be infinite, if you want to transfer large data over UDP datagram size, you need to add additional application layer protocol based on UDP.

  And even though there will still be enough to buffer data loss, the maximum length of UDP data for 1472

udp Code: 

server 
    server does not need to listen listener 
    does not need to accept a request receiving 
    reception data recvfrom (buffer size) 
    send data sendto (data, address) of 
the client: 
    without establishing a connection 
    reception data recvfrom (buffer size) 
    retransmission data sendto ( data, address)
Case: 

Server: 
from socket Import * #  Create a UDP-based scoket must manually specify the 
Server = socket (AF_INET, SOCK_DGRAM) 
server.bind (( " 127.0.0.1 " , 1688 )) the while True: 
    the Data, addr = server.recvfrom ( 1024 )
     Print ( " receive message from% s:% s "   % (addr, Data)) 
    server.sendto (data.upper (), addr) # server.close () 
client: Import Socket 
client = Socket. socket (socket.AF_INET, socket.SOCK_DGRAM)
 #









  UDP does not require the establishment of a link 

# data is transmitted to the specified recipient address 
client.sendto ( " Hello " .encode ( " UTF-. 8 " ), ( " 127.0.0.1 " , 1688 )) 

Data, addr = client.recvfrom (1024 )
 Print ( " receive message from% s:% s "   % (addr, Data)) 


client.close ()

2.UDP application: DNS

DNS: 
Domain Name System (Domain Name System) is a service of the Internet 

domain name: 
is the IP address of the alias to take, and in order when the query name and an address correspondence faster, it also divided the domain name to a different area. 
DNS role: 
translates domain names into IP addresses to connect to the server must know the IP 
alone ip ip it hard to remember so we are bound to a domain name and domain name string together a bunch of regular 

DNS server is terminal CS structure 
used by DNS UDP protocol for data transmission because of the small but high-speed requirements for a DNS service to many computer 

DNS is essentially a large database systems, which store the correspondence between the domain name and ip

3. Process

Process: 
refers to a program is running, is collectively referred to a series of processes, but also the operating system scheduler and the basic unit of resource allocation 

process is one way to achieve concurrent

4. The principle of multi-process - multi-channel technology

This concept comes from the process of the operating system, no operating system will not process 

the operating system: 
located between the application software and hardware equipment, in essence, is a software provided by the system kernel (manages all hardware resources) and the system interface (programmer to 
use interface), with an operating system running as a user operating the computer provided in the software on the hardware of two central role of the operating system:
a . control hardware, the hardware details hide ugly complex 2 the hardware disordered competition becomes orderly multi-channel technology: in order to improve the utilization of computers in the early development of the computer, at the same time can only run one program, to be run multiple applications at the same time, we need multi-channel technology multi-channel multi-channel technology It refers to multiple programs, multi-channel technology to solve multiple program competition or share the same resources (such as cpu) the
orderly scheduling problem solution that is multiplexed, multiplexed into time multiplexed on the multiplexing and space.
1 . Spatial multiplexing dividing the memory into different regions, each charged with a different program 2 . When a time multiplexed IO operation execution program, switch to another program to perform optical switching must be enough to save the current before switching in order to restore the status of the execution with the biggest problem is the complex on the space **: ** memory must be split between programs, this division requires the hardware level achieved by the operating system. If the
memory is not divided from each other, one can access the memory of another program, first of all is the loss of security, such as your qq program can access the operating system's memory, which means you can get all the permissions qq operating system . Second is the loss of stability, it is possible when a program crashes the program but also to other memory recovered, say the operating system to reclaim the memory,
the operating system crashes. The role of multi-channel technology: the computer can handle multiple tasks at the same time note: not necessarily improve multi-channel efficiency, if multiple computing tasks are so pure switching but reduces the efficiency; encountered IO operations should only switch ,
which can improve efficiency

 

Guess you like

Origin www.cnblogs.com/wangwei5979/p/10951443.html