Hi!
I'm trying to have a client detect what host a service is running on by doing a broadcast instead of telling the client what host to use.
Now, I when I try to send the date for the broadcast (on the sendto), I get a broken pipe:
Here's the output:
Code:
Traceback (most recent call last):
File "flisolclient.py", line 22, in <module>
sock.sendto("exit", ('<broadcast>', SERVICE_PORT))
socket.error: [Errno 32] Broken pipe
From strace:
Code:
sendto(3, "exit"..., 4, 0, {sa_family=AF_INET, sin_port=htons(9000), sin_addr=inet_addr("255.255.255.255")}, 16) = -1 EPIPE (Broken pipe)
--- SIGPIPE (Broken pipe) @ 0 (0) ---
Here's the offending code
Code:
SERVICE_PORT = 9000
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.setblocking(True)
sock.settimeout(5) # 5-second timeout to detect the service
sock.sendto("exit", ('<broadcast>', SERVICE_PORT))
server = 0
try:
buff, server = sock.recvfrom(2048)
except:
# probably, timed out
print "Couldn't find registration service"
exit(-1)
When I change the destination address to localhost (the service is running on this box for testing), I get the same error.
What am I missing?