Can't get UDP example to work
roy at panix.com
Sun Jul 26 18:53:59 CEST 2009
<148abf0f-c9e4-4156-8f16-e4e5615d350b at s6g2000vbp.googlegroups.com>,
Paul Barry <pauljbarry3 at gmail.com> wrote:
> host = '127.0.0.1' # Bind to all interfaces
This threw me off the track for a little while. The comment is wrong!
You're not binding to all interfaces, you're binding specifically to the
loopback interface. For what you're doing, it's fine, but the comment is
It's also a little weird that the example uses connect() and sendall().
Those are TCP-ish type constructs. They work with UDP sockets, but using
them sort of obscures the fundamental datagram nature of UDP.
Well, enough of that. The real problem seems to be right here:
> print "Looking for replies; press Ctrl-C or Ctrl-Break to stop."
> while 1:
> buf = s.recvfrom(2048)
Try adding sys.stdout.flush(), and it should work. Or change it to print.
I've never seen this book, but if this code really is verbatim from the
book, I'm not very impressed.
More information about the Python-list