LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 03-27-2008, 08:16 PM   #1
Hewson
Member
 
Registered: Feb 2007
Location: /home
Distribution: Kubuntu and CentOS
Posts: 214

Rep: Reputation: 32
Python socket: does not recieve anything


Hi LQers,

I am new to sockets in general. I have a program that is supposed to listen for udp packets sent to the broadcast address. I can see (sniffing with wireshark) that the packets are comming accross the interface, but nothing is returned. I do not know how to debug this problem or if any this is poorly configured or what.

Any suggestions would be great.
PHP Code:
# create udp socket
mysocket socket.socket(socket.AF_INETsocket.SOCK_DGRAM)
# allow send/recieve from broacast address
mysocket.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)
# allow the socket to be re-used
mysocket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
mysocket.bind((self.listen_addressself.listen_port))
# wait for a message for 30 seconds.
mysocket.settimeout(30)
#this times out every time.
data mysocketsocket.recv(1024
Thanks,

Steve
 
Old 03-27-2008, 08:48 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
is that all your code? take a look at the HOWTO for more info
 
Old 03-28-2008, 12:06 PM   #3
Hewson
Member
 
Registered: Feb 2007
Location: /home
Distribution: Kubuntu and CentOS
Posts: 214

Original Poster
Rep: Reputation: 32
ghostdog,

thanks for the response. No, that is not all of my code. (The actual full program includes around 800 lines of code) Most of it is not related to my socket issue, but I did realize I may have left out key part of my problem. Before I listen on the socket, I send a message:

PHP Code:

# create udp socket
mysocket socket.socket(socket.AF_INETsocket.SOCK_DGRAM)
# allow send/recieve from broacast address
mysocket.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)
# allow the socket to be re-used
mysocket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
mysocket.bind((self.listen_addressself.listen_port))

# send broadcast packet  (this packet is sent successfully.)
mysocket.sendto(packet.EncodePacket(),("255.255.255.255" ,self.emit_port))

# wait for a (response) message for 30 seconds.
mysocket.settimeout(30)
#this times out every time.
data mysocketsocket.recv(1024
Thanks for the pointer to that guide, for others in my position . . .
Here is a very useful guide that I started with: http://www.scribd.com/doc/134861/Soc...ng-with-python
The man page for socket is also useful.
 
Old 03-28-2008, 01:30 PM   #4
Hewson
Member
 
Registered: Feb 2007
Location: /home
Distribution: Kubuntu and CentOS
Posts: 214

Original Poster
Rep: Reputation: 32
Well I have figured out my problem:

It was not related to my socket code. It was related to the address I was attempting to bind to. My linux box has 4 interfaces. I used bind to specify which interface to use. I then sent a broadcast packet. The response is not sent to my address (that I specified in the the bind() ), but to 255.255.255.255.

My new problem: how do I specify an interface and listen for broadcast messages?
 
Old 03-28-2008, 01:53 PM   #5
Hewson
Member
 
Registered: Feb 2007
Location: /home
Distribution: Kubuntu and CentOS
Posts: 214

Original Poster
Rep: Reputation: 32
I'm going to just use two sockets: one for sending and a second for listening to the broadcast address.

Last edited by Hewson; 03-28-2008 at 01:54 PM.
 
  


Reply

Tags
python, sockets


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
fseek on a socket descriptor to discard socket buffer? Thinking Programming 1 12-06-2005 10:15 PM
python: full string isn't making it through socket cs-cam Programming 1 11-27-2005 12:20 AM
cannot read data at server socket, though client socket sends it jacques83 Linux - Networking 0 11-15-2005 02:58 PM
Unable to connect to UNIX socket /tmp/.esd/socket error while using grip dr_zayus69 Linux - Software 4 08-23-2005 08:28 PM
socket programming on-line books in python or in C pranith Programming 2 11-20-2004 11:58 AM


All times are GMT -5. The time now is 11:06 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration