TCP / UDP protocol communications --Python senior

Advanced Python

UDP-based protocol communication

Features: No connection (i.e., do not need to establish a connection), unreliable transmission (packet loss, out of order, but the probability is relatively low, as the lifting of a number of routers and other equipment, this probability becomes lower), best effort, SMS communication process and communication is similar, but the transmission efficiency is very high (ie fast communication),

Transmitting data packets using UDP protocol may send the data packet over the packet first to the starting, but the probability is relatively low

Communication between the step of:

1. Create a socket (Socket): equivalent to buying mobile phones, call Socket, the return value is a target

2. The socket is bound to address: the equivalent to the number on your phone, to the address (IP and port number) to prepare their own, the client program can omit this step (implicit binding)

3. send and receive data through the socket: the equivalent of text messaging via mobile phones

4. Close the socket, equivalent to turn off the phone

 

TCP protocol-based communications

Features: connection-oriented, reliable transmission (error check, the retransmission, the congestion control, out of order processing), and the communication process is similar to use his mobile phone, but the transmission efficiency is low (i.e., communication speed is slow),

Why Reliable: functional check data (i.e., error check), and when you check sent, if not the same, you would require retransmission, the congestion control, processing disorder, when the data packet is cut when the following data when the package first to make it in the buffer waiting, etc. in front of the packets we have reached together again to process

 

TCP client and server are unequal

 

TCP server (equivalent to the person answering the phone) implementation steps:

1. Create (listening) socket, equivalent to buying mobile phones

2. Bind address to the socket, which is equivalent to the number on the phone

3. The socket is set to listening state, it is equivalent to set the phone to standby mode

4. The client accepts the connection request (corresponding to a return connector socket), corresponding to the incoming call request receiving others

The send and receive data, corresponding to each call

6. Close the socket communication end (i.e., disconnected), equivalent to hang up the call ends

7. Close the listening socket, the equivalent of shutdown

 

TCP client (the equivalent of the caller) implementation steps:

1. Create a suite of word, equivalent to buying mobile phones

2. Give cellphone address, you can omit this step (implicit binding), which is equivalent to the number on the phone

3. The connection to the server, the equivalent of a telephone call others

4. The sending and receiving data, corresponding to each call

5. Close the socket, i.e. it is disconnected, corresponding to hang up the phone

 

 

Spread

1.TCP protocol does not support broadcast, it is a point

2. On the same machine TCP and UDP port numbers are the same, but the same protocol uses the same port will certainly be a problem

3. Do not just see the wire that the wire is, in fact, the electricity network

4. The communication network also known programming socket programming

The phone number is this phone address Mobile Unlimited Network

6. address not only the IP address, in fact, including the IP address and port number

7. The transport layer packaging, the original port number and destination port number

Network layer packaging, original and destination IP,

 

 

Guess you like

Origin www.cnblogs.com/yanruizhe/p/11305426.html