socket in python 2.2 vs 2.1
Jason Orendorff
jason at jorendorff.com
Tue Feb 26 12:52:58 EST 2002
Ivan Bykov wrote:
> IMHO, '255.255.255.255' is a valid IP number. This is
> number mask, use for broadcast packet.
> MvL> Just remove the connect call.
> Then program to work not will.
You are sending UDP broadcast packets?
I think the right way to do this is:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto(text, ('255.255.255.255', port))
That is, I think it is a mistake to call s.connect().
I believe most sockets libraries allow you to call connect()
on a DGRAM socket, and they interpret that as the programmer
setting a default destination for datagrams. However, it
seems more natural (and more faithful to the nature of UDP)
to specify the destination with sendto().
(Martin: 255.255.255.255 is the limited broadcast address.)
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list