Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-13-2009, 11:02 AM   #1
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,064
Blog Entries: 1

Rep: Reputation: 90
Question 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"
Old 04-13-2009, 12:53 PM   #2
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,064
Blog Entries: 1

Original Poster
Rep: Reputation: 90
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.


broadcast, ipv4, network, python, socket

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
network, broadcast addr scofiled83 Linux - Networking 5 11-10-2008 07:00 AM
Broadcast a messege to all nodes in network nebumt Linux - General 1 02-09-2006 01:51 AM
broadcast computer name on network? vdemuth Linux - Networking 5 11-10-2005 03:39 PM
/etc/network/interfaces broadcast problem nafai_anlashok Linux - Networking 2 04-26-2004 08:32 PM
how to broadcast tv over an ip network? andrewlkho Linux - General 5 08-10-2003 09:46 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:50 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration