This module forms the basis of all network communications in Python. It provides access to the BSD (Berkeley Software Distribution) socket interface and is available on most computer systems (including all Unix variants, Windows versions, Mac OS versions, BeOS, and OS/2). While the functionality available through the module is largely the same on all platforms, some differ. One is advised to check the socket documentation of one's operating system before using some of the more exotic functions of this module.
All usage of socket hinges on the creation of a socket object with socket.socket(). After the socket is created, several options are available. The documentation that follows comes from the official Python documentation.
More information can be found in the current Python documentation.
Functions:
The following functions are available through the socket module:[*] not available on all platforms!
- socket() -- create a new socket object
- socketpair() -- create a pair of new socket objects [*]
- fromfd() -- create a socket object from an open file descriptor [*]
- gethostname() -- return the current hostname
- gethostbyname() -- map a hostname to its IP number
- gethostbyaddr() -- map an IP number or hostname to DNS info
- getservbyname() -- map a service name and a protocol name to a port number
- getprotobyname() -- mape a protocol name (e.g. 'tcp') to a number
- ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order
- htons(), htonl() -- convert 16, 32 bit int from host to network byte order
- inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format
- inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)
- ssl() -- secure socket layer support (only available if configured)
- socket.getdefaulttimeout() -- get the default timeout value
- socket.setdefaulttimeout() -- set the default timeout value
Integer constants:
- SocketType -- type object for socket objects
- error -- exception raised for I/O errors
- has_ipv6 -- boolean value indicating if IPv6 is supported
Many other constants may be defined; these may be used in calls to the setsockopt() and getsockopt() methods.
- AF_INET, AF_UNIX -- socket domains (first argument to socket() call)
- SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)
Classes
The following classes are available through the socket module:__builtin__.object
SSL
_socketobject
_socketobject
exceptions.Exception
error
gaierror
herror
sslerror
timeout


