The socket Module

This is used for all low-level networking

  • Creation and manipulation of sockets
  • General purpose network functions (hostnames, data conversion, etc...)
  • A direct translation of the BSD socket interface.

Utility Functions

     socket.gethostbyname(hostname) # Get IP address for a host
     socket.gethostname()           # Name of local machine
     socket.ntohl(x)                # Convert 32-bit integer to host order
     socket.ntohs(x)                # Convert 16-bit integer to host order
     socket.htonl(x)                # Convert 32-bit integer to network order
     socket.htons(x)                # Convert 16-bit integer to network order 

Comments

  • Network order for integers is big-endian.
  • Host order may be little-endian or big-endian (depends on the machine).
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 88
July 17, 2000, beazley@cs.uchicago.edu
>>>