socket
index
/usr/lib/python2.2/socket.py

This module provides socket operations and some related functions.
On Unix, it supports IP (Internet Protocol) and Unix domain sockets.
On other systems, it only supports IP. Functions specific for a
socket are available as methods of the socket object.
 
Functions:
 
socket() -- create a new socket object
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)
 
 [*] not available on all platforms!
 
Special objects:
 
SocketType -- type object for socket objects
error -- exception raised for I/O errors
 
Integer constants:
 
AF_INET, AF_UNIX -- socket domains (first argument to socket() call)
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)
 
Many other constants may be defined; these may be used in calls to
the setsockopt() and getsockopt() methods.

 
Modules
            
_socket
 
Classes
            
exceptions.Exception
error
gaierror
herror
sslerror
_fileobject
_socketobject
 
class _fileobject
       
   Methods defined here:
__del__(self)
__init__(self, sock, mode, bufsize)
close(self)
fileno(self)
flush(self)
read(self, n=-1)
readline(self, limit=-1)
readlines(self, sizehint=0)
write(self, data)
writelines(self, list)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'socket'
 
class _socketobject
       
   Methods defined here:
__del__(self)
__init__(self, sock)
accept(self)
bind(self, *args)
close(self)
connect(self, *args)
connect_ex(self, *args)
dup(self)
fileno(self, *args)
getpeername(self, *args)
getsockname(self, *args)
getsockopt(self, *args)
listen(self, *args)
makefile(self, mode='r', bufsize=-1)
recv(self, *args)
recvfrom(self, *args)
send(self, *args)
sendall(self, *args)
sendto(self, *args)
setblocking(self, *args)
setsockopt(self, *args)
shutdown(self, *args)

Data and non-method functions defined here:
__doc__ = None
__module__ = 'socket'
_closedsocket = <class socket._closedsocket>
_m = 'shutdown'
_s = 'def %s(self, *args): return self._sock.%s(*args)\n\n'
 
class error(exceptions.Exception)
       
   Data and non-method functions defined here:
__doc__ = None
__module__ = 'socket'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class gaierror(error)
       
  
Method resolution order:
gaierror
error
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'socket'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class herror(error)
       
  
Method resolution order:
herror
error
exceptions.Exception

Data and non-method functions defined here:
__doc__ = None
__module__ = 'socket'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class sslerror(exceptions.Exception)
       
   Data and non-method functions defined here:
__doc__ = None
__module__ = 'socket'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
Functions
            
RAND_add(...)
RAND_add(string, entropy)
 
Mix string into the OpenSSL PRNG state.  entropy (a float) is a lower
bound on the entropy contained in string.
RAND_egd(...)
RAND_egd(path) -> bytes
 
Queries the entropy gather daemon (EGD) on socket path.  Returns number
of bytes read.  Raises socket.sslerror if connection to EGD fails or
if it does provide enough data to seed PRNG.
RAND_status(...)
RAND_status() -> 0 or 1
 
Returns 1 if the OpenSSL PRNG has been seeded with enough data and 0 if not.
It is necessary to seed the PRNG with RAND_add() on some platforms before
using the ssl() function.
fromfd(...)
fromfd(fd, family, type[, proto]) -> socket object
 
Create a socket object from the given file descriptor.
The remaining arguments are the same as for socket().
getaddrinfo(...)
socket.getaddrinfo(host, port [, family, socktype, proto, flags])
        --> List of (family, socktype, proto, canonname, sockaddr)
 
Resolve host and port into addrinfo struct.
getfqdn(name='')
Get fully qualified domain name from name.
 
An empty argument is interpreted as meaning the local host.
 
First the hostname returned by gethostbyaddr() is checked, then
possibly existing aliases. In case no FQDN is available, hostname
is returned.
gethostbyaddr(...)
gethostbyaddr(host) -> (name, aliaslist, addresslist)
 
Return the true host name, a list of aliases, and a list of IP addresses,
for a host.  The host argument is a string giving a host name or IP number.
gethostbyname(...)
gethostbyname(host) -> address
 
Return the IP address (a string of the form '255.255.255.255') for a host.
gethostbyname_ex(...)
gethostbyname_ex(host) -> (name, aliaslist, addresslist)
 
Return the true host name, a list of aliases, and a list of IP addresses,
for a host.  The host argument is a string giving a host name or IP number.
gethostname(...)
gethostname() -> string
 
Return the current host name.
getnameinfo(...)
socket.getnameinfo(sockaddr, flags) --> (host, port)
 
Get host and port for a sockaddr.
getprotobyname(...)
getprotobyname(name) -> integer
 
Return the protocol number for the named protocol.  (Rarely used.)
getservbyname(...)
getservbyname(servicename, protocolname) -> integer
 
Return a port number from a service name and protocol name.
The protocol name should be 'tcp' or 'udp'.
htonl(...)
htonl(integer) -> integer
 
Convert a 32-bit integer from host to network byte order.
htons(...)
htons(integer) -> integer
 
Convert a 16-bit integer from host to network byte order.
inet_aton(...)
inet_aton(string) -> packed 32-bit IP representation
 
Convert an IP address in string format (123.45.67.89) to the 32-bit packed
binary format used in low-level network functions.
inet_ntoa(...)
inet_ntoa(packed_ip) -> ip_address_string
 
Convert an IP address from 32-bit packed binary format to string format
ntohl(...)
ntohl(integer) -> integer
 
Convert a 32-bit integer from network to host byte order.
ntohs(...)
ntohs(integer) -> integer
 
Convert a 16-bit integer from network to host byte order.
ssl(...)
ssl(socket, [keyfile, certfile]) -> sslobject
 
Data
             AF_APPLETALK = 5
AF_AX25 = 3
AF_BRIDGE = 7
AF_INET = 2
AF_INET6 = 10
AF_IPX = 4
AF_NETROM = 6
AF_PACKET = 17
AF_ROSE = 11
AF_UNIX = 1
AF_UNSPEC = 0
AF_X25 = 9
AI_CANONNAME = 2
AI_NUMERICHOST = 4
AI_PASSIVE = 1
EAI_ADDRFAMILY = -9
EAI_AGAIN = -3
EAI_BADFLAGS = -1
EAI_FAIL = -4
EAI_FAMILY = -6
EAI_MEMORY = -10
EAI_NODATA = -5
EAI_NONAME = -2
EAI_SERVICE = -8
EAI_SOCKTYPE = -7
EAI_SYSTEM = -11
INADDR_ALLHOSTS_GROUP = -536870911
INADDR_ANY = 0
INADDR_BROADCAST = -1
INADDR_LOOPBACK = 2130706433
INADDR_MAX_LOCAL_GROUP = -536870657
INADDR_NONE = -1
INADDR_UNSPEC_GROUP = -536870912
IPPORT_RESERVED = 1024
IPPORT_USERRESERVED = 5000
IPPROTO_AH = 51
IPPROTO_DSTOPTS = 60
IPPROTO_EGP = 8
IPPROTO_ESP = 50
IPPROTO_FRAGMENT = 44
IPPROTO_GRE = 47
IPPROTO_HOPOPTS = 0
IPPROTO_ICMP = 1
IPPROTO_ICMPV6 = 58
IPPROTO_IDP = 22
IPPROTO_IGMP = 2
IPPROTO_IP = 0
IPPROTO_IPIP = 4
IPPROTO_IPV6 = 41
IPPROTO_NONE = 59
IPPROTO_PIM = 103
IPPROTO_PUP = 12
IPPROTO_RAW = 255
IPPROTO_ROUTING = 43
IPPROTO_RSVP = 46
IPPROTO_TCP = 6
IPPROTO_TP = 29
IPPROTO_UDP = 17
IPV6_JOIN_GROUP = 20
IPV6_LEAVE_GROUP = 21
IPV6_MULTICAST_HOPS = 18
IPV6_MULTICAST_IF = 17
IPV6_MULTICAST_LOOP = 19
IPV6_UNICAST_HOPS = 16
IP_ADD_MEMBERSHIP = 35
IP_DEFAULT_MULTICAST_LOOP = 1
IP_DEFAULT_MULTICAST_TTL = 1
IP_DROP_MEMBERSHIP = 36
IP_HDRINCL = 3
IP_MAX_MEMBERSHIPS = 20
IP_MULTICAST_IF = 32
IP_MULTICAST_LOOP = 34
IP_MULTICAST_TTL = 33
IP_OPTIONS = 4
IP_RECVOPTS = 6
IP_RECVRETOPTS = 7
IP_RETOPTS = 7
IP_TOS = 1
IP_TTL = 2
MSG_CTRUNC = 8
MSG_DONTROUTE = 4
MSG_DONTWAIT = 64
MSG_EOR = 128
MSG_OOB = 1
MSG_PEEK = 2
MSG_TRUNC = 32
MSG_WAITALL = 256
NI_DGRAM = 16
NI_MAXHOST = 1025
NI_MAXSERV = 32
NI_NAMEREQD = 8
NI_NOFQDN = 4
NI_NUMERICHOST = 1
NI_NUMERICSERV = 2
PACKET_BROADCAST = 1
PACKET_FASTROUTE = 6
PACKET_HOST = 0
PACKET_LOOPBACK = 5
PACKET_MULTICAST = 2
PACKET_OTHERHOST = 3
PACKET_OUTGOING = 4
PF_PACKET = 17
SOCK_DGRAM = 2
SOCK_RAW = 3
SOCK_RDM = 4
SOCK_SEQPACKET = 5
SOCK_STREAM = 1
SOL_IP = 0
SOL_SOCKET = 1
SOL_TCP = 6
SOL_UDP = 17
SOMAXCONN = 128
SO_ACCEPTCONN = 30
SO_BROADCAST = 6
SO_DEBUG = 1
SO_DONTROUTE = 5
SO_ERROR = 4
SO_KEEPALIVE = 9
SO_LINGER = 13
SO_OOBINLINE = 10
SO_RCVBUF = 8
SO_RCVLOWAT = 18
SO_RCVTIMEO = 20
SO_REUSEADDR = 2
SO_SNDBUF = 7
SO_SNDLOWAT = 19
SO_SNDTIMEO = 21
SO_TYPE = 3
SSL_ERROR_SSL = 1
SSL_ERROR_SYSCALL = 5
SSL_ERROR_WANT_READ = 2
SSL_ERROR_WANT_WRITE = 3
SSL_ERROR_WANT_X509_LOOKUP = 4
SSL_ERROR_ZERO_RETURN = 6
TCP_MAXSEG = 2
TCP_NODELAY = 1
__all__ = ['getfqdn', 'AF_APPLETALK', 'AF_AX25', 'AF_BRIDGE', 'AF_INET', 'AF_INET6', 'AF_IPX', 'AF_NETROM', 'AF_PACKET', 'AF_ROSE', 'AF_UNIX', 'AF_UNSPEC', 'AF_X25', 'AI_CANONNAME', 'AI_NUMERICHOST', 'AI_PASSIVE', 'EAI_ADDRFAMILY', 'EAI_AGAIN', 'EAI_BADFLAGS', 'EAI_FAIL', ...]
__file__ = '/usr/lib/python2.2/socket.pyc'
__name__ = 'socket'
_socketmethods = ('bind', 'connect', 'connect_ex', 'fileno', 'listen', 'getpeername', 'getsockname', 'getsockopt', 'setsockopt', 'recv', 'recvfrom', 'send', 'sendall', 'sendto', 'setblocking', 'shutdown')