Reputation: 441
I am trying to receive data, but it is taking FOREVER to receive.
I have tried a couple of things, like changing the Buffer size, but I am still not having any luck. This is to make me believe that it might not be an error with my code, but maybe the network.
import socket
UDP_IP = ''
UDP_PORT = 1500
BUFFER_SIZE = 1024
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print("about to bind")
sock.bind((UDP_IP, UDP_PORT))
while True:
try:
print('testing')
message = sock.recv(BUFFER_SIZE)
print("Got data:", repr(message))
except KeyboardInterrupt:
break
I am expecting to receive a message over the network. Thank you to all of those who reply in advance.
Upvotes: 0
Views: 65
Reputation: 136208
Your code works as expected: it receives messages and prints them.
I tested it with the following command:
echo Hello | nc -u 127.0.0.1 1500
Make sure your router and local firewalls allow your UDP traffic through.
Upvotes: 1