One, Socket UDP
UDP is non-linked, starting at which end will not error
UDP (User Datagram Protocol, Subscriber Datagram Protocol) is non-connected, message-oriented, providing efficient service. The Block merging optimization algorithm is not used, because UDP supports a one-to-many pattern, so the receiver Skbuff (socket buffer) uses a chain structure to record each incoming UDP packet, in each UDP packet there is a message header (message source address, port and other information), so for the receiving end , it is easy to distinguish between the processing. that is, message-oriented communication is a message-protected boundary.
Server
# Server = socket () # Create a server socket ss.bind () # bind server socket Inf_loop: # server infinite loop # dialog (receive and send) ss.close () # Close server sockets
Client
# Client = socket () # Create client socket Comm_loop: # communication Loop cs.sendto ()/ Cs.recvfrom () # Dialog (send/Receive)Cs.close () # close client sockets
A simple example of UDP sockets
1 #_*_coding:utf-8_*_2 __author__='Linhaifeng'3 ImportSocket4Ip_port= ('127.0.0.1', 9000)5bufsize=10246Udp_server_client=Socket.socket (Socket.af_inet,socket. SOCK_DGRAM)7 8 Udp_server_client.bind (Ip_port)9 Ten whileTrue: OneMsg,addr=Udp_server_client.recvfrom (BUFSIZE) A Print(MSG,ADDR) - -Udp_server_client.sendto (Msg.upper (), addr)
Server
1 #_*_coding:utf-8_*_2 __author__='Linhaifeng'3 ImportSocket4Ip_port= ('127.0.0.1', 9000)5bufsize=10246Udp_server_client=Socket.socket (Socket.af_inet,socket. SOCK_DGRAM)7 8 whileTrue:9Msg=input ('>>:'). Strip ()Ten if notMsgContinue One AUdp_server_client.sendto (Msg.encode ('Utf-8'), Ip_port) - -Back_msg,addr=Udp_server_client.recvfrom (BUFSIZE) the Print(Back_msg.decode ('Utf-8'), addr)
Client
Second, the operating system
Refer to Teacher's blog: http://www.cnblogs.com/linhaifeng/p/6295875.html
1. What is an operating system?
Operating system is a control program that is located between computer hardware and software to coordinate management and control of computer hardware and software resources.
2. Two major functions of the operating system:
1, the complex ugly hardware operations are packaged into a beautiful interface, provided to the application
2, the process of hardware competition to change the orderly
Third, Multi theory
Multi-channel technology refers to multiple programs, multi-channel technology is to solve multiple programs to compete or share the same resource (such as the CPU) of the orderly scheduling problem, the solution is multiplexing, multiplexing is divided into The reuse of time and the reuse of space .
1, space reuse : The memory is divided into several parts, each part into a program, so that the same time in memory has a multi-channel program.
2, time reuse : When a program is waiting for I/O, another program can use the CPU, if the memory can hold enough jobs at the same time, the CPU utilization can be close to 100%, similar to our primary school mathematics learned co-ordinated approach . (The operating system uses multi-channel technology, you can control the process of switching, or the process to compete for CPU execution permissions.) This kind of switchover will not only occur when a process encounters Io, a process that consumes CPU time too long will switch , or the operating system takes the CPU's execution rights)
Detailed
Modern computers or networks are multi-user, multiple users not only share hardware, but also share files, databases and other information, sharing means conflict and disorder.
The operating system is primarily used to
1. Log which program uses what resources
2. Allocation of resource requests
3. Mediate conflicting resource requests for different programs and users.
We can summarize the functions of the above operating system as follows: processing requests from multiple (multiple-way) shared (shared-as-reuse) resources initiated by several programs, for short, multiplexing multiplexing, two ways
1. Time reuse when a resource is reused in time, different programs or users take turns to use it, and the first program gets the resource used at the end, in the turn to the second ... The third one ...
For example: There is only one CPU, multiple programs need to run on the CPU, the operating system first distributed the CPU to the first program, the program is running long enough (the length of time by the algorithm of the operating system) or encountered an I/O blocking, the operating system will allocate the CPU to the next program, and so on, Until the first program is again assigned to the CPU and then run again, because the CPU switching speed quickly, to the user's feeling is that these programs are running at the same time, or is concurrent, or pseudo-parallel. As for how resources are used for time reuse, or who should be the next program to run, and how long a task needs to run, these are the work of the operating system.
2. Space reuse each customer acquires a small subset of resources in a large resource, reducing the time it takes to queue up for resources.
For example, multiple running programs go into memory at the same time, and the hardware layer provides a protection mechanism to ensure that the respective memory is split and controlled by the operating system, which is much more efficient than one program exclusive memory and one queue into memory. Other resources for space reuse also have disks, and in many systems, one disk saves files for many users at the same time. Allocating disk space and documenting who is using which disk block is a typical task for operating system resource management. The combination of these two approaches is a multi-channel technique.
The biggest problem with spatial multiplexing is that memory must be split between programs, which needs to be implemented at the hardware level and controlled by the operating system. If the memory is not split, one program can access the memory of the other program
The first loss is security, such as your QQ program can access the operating system's memory, which means that your QQ can get all the operating system permissions.
Second, the loss of stability, a program crashes when it is possible to recycle the memory of other programs, for example, the memory of the operating system is recycled, the operating system crashes.
April 23 Python Learning summary socket UDP and operating system theory, multi-channel theory