LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
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: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:14 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration