-   Programming (
-   -   python: network broadcast not working (

eantoranz 04-13-2009 11:02 AM

python: network broadcast not working

I'm trying to do a network broadcast so that a client can locate a service on a remote machine without having to tell it what the server host is.

I'm following this example:

with strace, I can see this:

sendto(3, "exit"..., 4, 0, {sa_family=AF_INET, sin_port=htons(9000), sin_addr=inet_addr("")}, 16) = 4
poll([{fd=3, events=POLLIN}], 1, 10000) = 0 (Timeout)

However, I'm checking with netstat and lsof to see if there's a process trying to connect to port 9000 and there's nothing of that. ALso, I can't see any traffic going out to port 9000 on any interface (either loopback or ethernet). What am I doing wrong?

Here's the offending code:

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.settimeout(10) # 5-second timeout to detect the service
sock.sendto("exit", ('<broadcast>', SERVICE_PORT))
server = 0
    buff, server = sock.recvfrom(2048)
    # probably, timed out
    print "Couldn't find registration service"

eantoranz 04-13-2009 12:53 PM

I think the problem is that I was using TCP on the server and UDP on the client. :-S

Now I've got a broken pipe, so I think I'll create another post.

All times are GMT -5. The time now is 06:17 PM.