sockets -- basic udp client
roy at panix.com
Sun Feb 17 15:44:20 CET 2008
In article "rluse1 at gmail.com" <rluse1 at gmail.com> wrote:
> If you don't care about the address of the sender, e.g. you are not
> going to send anything back, is there an advantage to using recv()?
At the system call level, recv() is marginally faster since there's less
data to pass back and forth between the kernel and user space. Not that
this is likely to be significant in any real-world application.
The bigger advantage to recv() is that the interface is simpler, so there's
less code to write. For the C interface, using recv() instead of
recvfrom() frees you from having to pass in two arguments that you're not
going to use. From the Python interface, it frees you from having to
unpack the tuple that recvfrom() returns. Instead of:
data, address = recvfrom(bufsize)
data = recv(bufsize)
It's not just a bunch less typing, it's also easier to understand. You
don't leave some future maintainer of your code scratching their head
trying to figure out where 'address' is used, when in fact, it's not.
More information about the Python-list