The tcp/udp of Python learning

Source: Internet
Author: User

TCP/UDP are both network programming (sockets) based on the C/s structure of the program.

UDP: Non-reliable connection speed, server: Create socket binding IP and port directly from the specified IP and port to receive data without listening; client: Create socket, receive data directly, do not need to establish a connection.

s = socket.socket (socket.af_inet, socket. SOCK_DGRAM)
# Bound Port:
S.bind (' 127.0.0.1 ', 9999)

S.recvfrom (1024x768) #接收数据.

TCP: Reliable connection, the client also needs to establish a connection s.connect ((' 127.0.0.1 ', 9999)), server: Need to listen to S.listen (5),

Next, the server program passes a permanent loop to accept the connection from the client, and accept () waits for and returns a client connection:
While True:
# Accept a new connection:
Sock, addr = S.accept ()
# Create a new thread to handle the TCP connection:
t = Threading. Thread (Target=tcplink, args= (sock, addr))
T.start ()

The tcp/udp of Python learning

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.