[newbie] trying socket as a replacement for nc

Chris Angelico rosuav at gmail.com
Sun Dec 15 11:04:58 EST 2013


On Mon, Dec 16, 2013 at 2:51 AM, Roy Smith <roy at panix.com> wrote:
> In article <l8kh1r$bj8$1 at reader1.panix.com>,
>  Grant Edwards <invalid at invalid.invalid> wrote:
>
>> UDP is a a _datagram_ service. Either all the bytes in a write()
>> should get sent or none of them. Sending a paritial datagram is _not_
>> a valid option.
>
> I would agree with the above if you said send() instead of write().
> Python socket objects don't have write() methods, file objects do.  You
> can wrap a file around a socket with socket.makefile(), but I'm not sure
> I would expect the UDP record boundary semantics to be honored once you
> did that.

The underlying C API allows you, on Unix-like systems at least, to use
the standard write() function to send UDP packets (as long as you
first connect() - otherwise you need sendto() to specify a
destination). I don't usually use that method, but I would expect that
one call to write() becomes one UDP packet.

How that works with socket.makefile() in Python I have no idea.

ChrisA



More information about the Python-list mailing list