gevent._socket2
– Python 2 socket module¶Caution
Some of the docstrings are automatically generated and may be correct for Python 3 but not Python 2. Please see the standard library documentation.
Python 2 socket module.
alias of OSError
Bases: OSError
Exception.add_note(note) – add a note to the exception
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
POSIX exception code
exception filename
second exception filename
exception strerror
Bases: OSError
Exception.add_note(note) – add a note to the exception
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
POSIX exception code
exception filename
second exception filename
exception strerror
alias of TimeoutError
Bases: SocketMixin
gevent socket.socket for Python 2.
This object should have the same API as the standard library socket linked to above. Not all methods are specifically documented here; when they are they may point out a difference to be aware of or may document a method the standard library does not.
Changed in version 1.5.0: This object is a context manager, returning itself, like in Python 3.
Bind the socket to a local address. For IP sockets, the address is a pair (host, port); the host must refer to the local host. For raw packet sockets the address is a tuple (ifname, proto [,pkttype [,hatype [,addr]]])
Connect to address.
Changed in version 20.6.0: If the host part of the address includes an IPv6 scope ID,
it will be used instead of ignored, if the platform supplies
socket.inet_pton()
.
This is like connect(address), but returns an error code (the errno value) instead of raising an exception when an error occurs.
Return a new socket object connected to the same system resource. Note, that the new socket does not inherit the timeout.
Return the integer file descriptor of the socket.
Returns whether the socket will approximate blocking behaviour.
New in version 1.3a2: Added in Python 3.7.
Return the address of the remote endpoint. For IP sockets, the address info is a pair (hostaddr, port).
Return the address of the local endpoint. The format depends on the address family. For IPv4 sockets, the address info is a pair (hostaddr, port).
Get a socket option. See the Unix manual for level and option. If a nonzero buffersize argument is given, the return value is a string of that length; otherwise it is an integer.
Returns the timeout in seconds (float) associated with socket operations. A timeout of None indicates that timeouts on socket operations are disabled.
Enable a server to accept connections. If backlog is specified, it must be at least 0 (if it is lower, it is set to 0); it specifies the number of unaccepted connections that the system will allow before refusing new connections. If not specified, a default reasonable value is chosen.
Receive up to buffersize bytes from the socket. For the optional flags argument, see the Unix manual. When no data is available, block until at least one byte is available or until the remote end is closed. When the remote end is closed and all data is read, return the empty string.
A version of recv() that stores its data into a buffer rather than creating a new string. Receive up to buffersize bytes from the socket. If buffersize is not specified (or 0), receive up to the size available in the given buffer.
See recv() for documentation about the flags.
Like recv(buffersize, flags) but also return the sender’s address info.
Like recv_into(buffer[, nbytes[, flags]]) but also return the sender’s address info.
Send a data string to the socket. For the optional flags argument, see the Unix manual. Return the number of bytes sent; this may be less than len(data) if the network is busy.
Send a data string to the socket. For the optional flags argument, see the Unix manual. This calls send() repeatedly until all data is sent. If an error occurs, it’s impossible to tell how much data has been sent.
Like send(data, flags) but allows specifying the destination address. For IP sockets, the address is a pair (hostaddr, port).
Set the socket to blocking (flag is true) or non-blocking (false). setblocking(True) is equivalent to settimeout(None); setblocking(False) is equivalent to settimeout(0.0).
Set a socket option. See the Unix manual for level and option. The value argument can either be an integer, a string buffer, or None, optlen.
Set a timeout on socket operations. ‘timeout’ can be a float, giving in seconds, or None. Setting a timeout of None disables the timeout feature and is equivalent to setblocking(1). Setting a timeout of zero is the same as setblocking(0).
Shut down the reading side of the socket (flag == SHUT_RD), the writing side of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR).
Read-only access to the address family for this socket.
the socket protocol
Read-only access to the socket type.
Convenience function which creates a SOCK_STREAM type socket bound to address (a 2-tuple (host, port)) and return the socket object.
family should be either AF_INET or AF_INET6. backlog is the queue size passed to socket.listen(). reuse_port dictates whether to use the SO_REUSEPORT socket option. dualstack_ipv6: if true and the platform supports it, it will create an AF_INET6 socket able to accept both IPv4 or IPv6 connections. When false it will explicitly disable this option on platforms that enable it by default (e.g. Linux).
>>> with create_server(('', 8000)) as server:
... while True:
... conn, addr = server.accept()
... # handle new connection
Resolve host and port into list of address info entries.
Translate the host/port argument into a sequence of 5-tuples that contain all the necessary arguments for creating a socket connected to that service. host is a domain name, a string representation of an IPv4/v6 address or None. port is a string service name such as ‘http’, a numeric port number or None. By passing None as the value of host and port, you can pass NULL to the underlying C API.
The family, type and proto arguments can be optionally specified in order to narrow the list of addresses returned. Passing zero as a value for each of these arguments selects the full range of results.
See also
Returns the default timeout in seconds (float) for new socket objects. A value of None indicates that new socket objects have no timeout. When the socket module is first imported, the default is None.
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 from gethostname() is returned.
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.
See also
Return the IP address (a string of the form ‘255.255.255.255’) for a host.
See also
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. Resolve host and port into list of address info entries.
See also
Return the current host name.
Return the protocol number for the named protocol. (Rarely used.)
Return a port number from a service name and protocol name. The optional protocol name, if given, should be ‘tcp’ or ‘udp’, otherwise any protocol will match.
Return the service name from a port number and protocol name. The optional protocol name, if given, should be ‘tcp’ or ‘udp’, otherwise any protocol will match.
Return True if the platform supports creating a SOCK_STREAM socket which can handle both AF_INET and AF_INET6 (IPv4 / IPv6) connections.
Convert a 32-bit integer from host to network byte order.
Convert a 16-bit unsigned integer from host to network byte order.
Convert an IP address in string format (123.45.67.89) to the 32-bit packed binary format used in low-level network functions.
Convert an IP address from 32-bit packed binary format to string format
Convert a packed IP address of the given family to string format.
Convert an IP address from string format to a packed string suitable for use with low-level network functions.
Convert a 32-bit integer from network to host byte order.
Convert a 16-bit unsigned integer from network to host byte order.
descriptors, msg_flags, address)
Receive up to maxfds file descriptors returning the message data and a list containing the descriptors.
Send the list of file descriptors fds over an AF_UNIX socket.
Set the default timeout in seconds (float) for new socket objects. A value of None indicates that new socket objects have no timeout. When the socket module is first imported, the default is None.
Sets the hostname to name.
Next page: gevent.ssl
– Secure Sockets Layer (SSL/TLS) module