Python in socket.error: [Errno 10022]

Source: Internet
Author: User

This error always occurs when UDP is turned on using the socket module in Python

Let's put the error code down.

Server

Import Socketimport random,times = Socket.socket (socket.af_inet, socket. SOCK_DGRAM) host = ' 127.0.0.1 ' port = 21567addr = (host, port) if __name__ = = ' __main__ ': s.bind (addr) while True:time.sleep (5 data = Random.random () print (' SendTo data:%s '%str (data)) S.sendto (str (data), addr) S.close ()

Client

Import sockets = Socket.socket (socket.af_inet, socket. SOCK_DGRAM) While true:data,addr = S.recvfrom (1024x768) q.put (data) Time.sleep (Random.random ())


This code at run time, always appeared errno 10022, looked for an afternoon only to find out


Reason:

When a UDP needs to accept data, first let the operating system know that the port on which the program is located, that is, the need to bind

And I am sending data through the server, the client to connect the data, therefore, clients do not know which Port belongs to their own

Which is why the error has always occurred.


Python in socket.error: [Errno 10022]

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.