LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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
 
Search this Thread
Old 04-13-2009, 12:59 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
Question python: socket broadcast produces a broken pipe


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?
 
Old 04-14-2009, 06:20 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by eantoranz View Post
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) ---
Uh? Trying to broadcast over the entire internet?

Quote:
Originally Posted by eantoranz View Post
Here's the offending code
Code:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
You're using TCP for broadcasting. This looks strange (wrong?) to me. I'm by no means an expert, so I may be wrong at this.
 
Old 04-14-2009, 08:24 AM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Original Poster
Rep: Reputation: 83
Yes.... I gave up that route. I'm trying with zeroconf... but I'm stuck there as well:

http://www.linuxquestions.org/questi...server-718899/

Any ideas?
 
  


Reply

Tags
broadcast, 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
How to broadcast with Java Socket manolakis Programming 3 12-14-2008 01:44 AM
Stop perl socket server broken pipe or exiting son_t Programming 1 10-25-2007 03:52 AM
broadcast (udp) socket - multi processes emarri Programming 1 09-25-2006 06:06 AM
Why Does a Broadcast on a Raw Socket get echoed back to me? btn_paragon Programming 5 09-09-2005 07:32 AM
ifconfig usb0 produces "Broken pipe" JohnKFT Slackware 0 11-13-2004 04:56 PM


All times are GMT -5. The time now is 05:23 PM.

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