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.
socket
(family=2, type=1, proto=0, _sock=None)[source]¶Bases: gevent._socketcommon.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
(address)¶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]])
connect
(address)¶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()
.
connect_ex
(address) → errno¶This is like connect(address), but returns an error code (the errno value) instead of raising an exception when an error occurs.
dup
() → socket object[source]¶Return a new socket object connected to the same system resource. Note, that the new socket does not inherit the timeout.
fileno
() → integer¶Return the integer file descriptor of the socket.
getblocking
()¶Returns whether the socket will approximate blocking behaviour.
New in version 1.3a2: Added in Python 3.7.
getpeername
() → address info¶Return the address of the remote endpoint. For IP sockets, the address info is a pair (hostaddr, port).
getsockname
() → address info¶Return the address of the local endpoint. For IP sockets, the address info is a pair (hostaddr, port).
getsockopt
(level, option[, buffersize]) → value¶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.
gettimeout
() → timeout¶Returns the timeout in seconds (float) associated with socket operations. A timeout of None indicates that timeouts on socket operations are disabled.
listen
(backlog)¶Enable a server to accept connections. The backlog argument 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.
sendall
(data[, flags])[source]¶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.
setblocking
(flag)¶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).
setsockopt
(level, option, value)¶Set a socket option. See the Unix manual for level and option. The value argument can either be an integer or a string.
settimeout
(timeout)¶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).
shutdown
(flag)¶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).
SocketType
¶alias of gevent._socket2.socket
create_connection
(address, timeout=None, source_address=None, *, all_errors=False) → socket[source]¶Connect to address and return the gevent.socket.socket
object.
Convenience function. Connect to address (a 2-tuple (host,
port)
) and return the socket object. Passing the optional
timeout parameter will set the timeout on the socket instance
before attempting to connect. If no timeout is supplied, the
global default timeout setting returned by
getdefaulttimeout()
is used. If source_address is set it
must be a tuple of (host, port) for the socket to bind as a source
address before making the connection. A host of ‘’ or port 0 tells
the OS to use the default.
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()
.
Changed in version 22.08.0: Add the all_errors argument. This only has meaning on Python 3.11; it is a programming error to pass it on earlier versions.
getaddrinfo
(host, port, family=0, socktype=0, proto=0, flags=0)[source]¶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
gethostbyname
(host) → address[source]¶Return the IP address (a string of the form ‘255.255.255.255’) for a host.
See also
gethostbyname_ex
(host) -> (name, aliaslist, addresslist)[source]¶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
gethostbyaddr
(ip_address) -> (name, aliaslist, addresslist)[source]¶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
Next page: gevent.ssl
– Secure Sockets Layer (SSL/TLS) module