Cyber Lis Cyber Lis - 1 year ago 106
Python Question

Why python raises exception on udp recvfrom

I have realy simple python27 script on Windows10

It is just sends messages and waits for reply using udp socket

import socket

UDP_IP = ""
UDP_PORT = 5005
MESSAGE = "Hello, World!"

print "UDP target IP:", UDP_IP
print "UDP target port:", UDP_PORT
print "message:", MESSAGE

sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))

On Windows 10 it raises exception

Traceback (most recent call last):
File "", line 14, in <module>
print sock.recv(1200)
socket.error: [Errno 10054]

On Linux it works fine.

What i am doing wrong ?


I found solution here Windows UDP sockets: recvfrom() fails with error 10054 Author made the same. He ignores this error. But maybe it is true way of solving this problem. I just put recvfrom in while and wrapped it with try..except And I ignore any errors. It worked for me