sockets -- basic udp client

7stud bbxx789_05ss at yahoo.com
Sat Feb 16 16:30:18 EST 2008


On Feb 16, 6:32 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> >> That example is plain wrong; looks like some TCP code but with  
> >> SOCK_STREAM  
> >> blindy replaced with SOCK_DGRAM. connect, sendall and recv are not used  
> >> for UDP; sendto and recvfrom are used instead. There are some examples  
> >> in  
> >> the Demo python directory.
>
> > Yes, I agree it's a poor example--it's from 'Foundations of Python
> > Network Programming'--but it does 'work'.  It also doesn't appear to
> > be a tcp client that was converted too directly into a udp client
> > because the previously presented tcp examples are different.
>
> Ok, you *can* use those functions with datagrams too, but it's confusing  
> (at least for the very first UDP example!)
>

Yes, I agree.  The book is well written, but the introductory examples
and a lack of explanation of the finer details is a disaster.


> > Another question I have pertains to the docs here:
>
> > getservbyname(servicename[, protocolname])
> > Translate an Internet service name and protocol name to a port number
> > for that service. The optional protocol name, if given, should be
> > 'tcp' or 'udp', otherwise any protocol will match.
>
> > What does a 'servicename' look like?
>
> py> import socket
> py> socket.getservbyname("http")
> 80
> py> socket.getservbyname("smtp")
> 25
>
> On Linux the mapping ports<->services is in /etc/services; on Windows see  
> %windir%\system32\drivers\etc\services
>
> --
> Gabriel Genellina

Thanks.



More information about the Python-list mailing list