Python Learning Notes (46) network programming (2)-UDP programming

Source: Internet
Author: User

Excerpt: Https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/ 001432004977916a212e2168e21449981ad65cd16e71201000

TCP is to establish a reliable connection , and both sides of the communication can send data in the form of a stream . In contrast to TCP,UDP is a non-connection-oriented protocol .

When using the UDP protocol, you do not need to establish a connection, just need to know the other side's IP address and port number , you can directly send packets. But I don't know if I can get there.

Although the transmission of data with UDP is unreliable, its advantage is that it is faster than TCP, and the UDP protocol can be used for data that does not require reliable arrival .

Let's take a look at how the data is transmitted over the UDP protocol. Like TCP, both sides of the communication using UDP are also divided into clients and servers. The server first needs to bind the port :

s = Socket.socket (socket.af_inet, socket. SOCK_DGRAM)#  bound port:s.bind (('127.0.0.1', 9999))

When a socket is created, the SOCK_DGRAM type of the socket specified is UDP. The binding port is the same as TCP, but does not require a listen() method to be called , but instead receives data from any client directly:

Python Learning Notes (46) network programming (2)-UDP programming

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.