socket.sendto / UDP problem

Todd Walter twalter at rogers.com
Thu Oct 21 12:50:32 EDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, 21 Oct 2010 17:03:58 +0100
MRAB <python at mrabarnett.plus.com> wrote:

> On 21/10/2010 15:57, Todd Walter wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > On Thu, 21 Oct 2010 00:07:58 +0100
> > MRAB<python at mrabarnett.plus.com>  wrote:
> >
> >>>
> >> [snip]
> >>
> >> The docs for 'sendto' say:
> >>
> >>       """The socket should not be connected to a remote socket,
> >> since the destination socket is specified by address."""
> >>
> >> Could your problem be caused by you binding the socket to a source
> >> port, so it's going out both to the bound port _and_ the one given
> >> the binding?
> >>
> >> Have you tried using two sockets, one outgoing and the other
> >> incoming?
> >>
> >> BTW, your code for handling the response doesn't cope with it
> >> coming in a bit at a time. It loops discard any previous data from
> >> the previous iteration.
> >>
> >> Also, it's more Pythonic to say:
> >>
> >>       while '\r' not in response:
> >>           ...
> > I haven't bound the socket to a remote port, as I read it; it's
> > bound to a source port (192.168.10.2:2260, the local machine) and
> > just transmits to an address with a port glommed on
> > (192.168.10.1:2002, the PLC).
> [snip]
> What I meant was that you're using 'pcSocket' for both directions and
> using .bind on it.
> 
> Try creating two sockets, 'pcInSocket' and 'pcOutSocket', and bind
> only pcOutSocket.

Ah, I comprehend now.  Thanks!

- - Todd
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (GNU/Linux)

iEYEARECAAYFAkzAb14ACgkQwnknPuQqPIOYEwCeNQNjGSQ/fwy2kLn862lY4fIk
OosAn0WplhDaFE3gVVmyLHrFwfwjfLFm
=j9fb
-----END PGP SIGNATURE-----


More information about the Python-list mailing list