LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 04-13-2009, 11:02 AM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,956
Blog Entries: 1

Rep: Reputation: 81
Question python: network broadcast not working


Hi!

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:
http://www.java2s.com/Code/Python/Ne...castSender.htm

with strace, I can see this:
Code:
sendto(3, "exit"..., 4, 0, {sa_family=AF_INET, sin_port=htons(9000), sin_addr=inet_addr("255.255.255.255")}, 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:
Code:
SERVICE_PORT = 9000
import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.setblocking(True)
sock.settimeout(10) # 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)
 
Old 04-13-2009, 12:53 PM   #2
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,956
Blog Entries: 1

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


Reply

Tags
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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


All times are GMT -5. The time now is 08:07 AM.

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