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]