gevent._socket2
– Python 2 socket module¶Python 2 socket module.
alias of OSError
Bases: OSError
Bases: OSError
Bases: OSError
alias of gevent._socket2.socket
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.
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()
.
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. Note that in case the received integer does not fit in 16-bit unsigned integer, but does fit in a positive C int, it is silently truncated to 16-bit unsigned integer. However, this silent truncation feature is deprecated, and will raise an exception in future versions of Python.
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. Note that in case the received integer does not fit in 16-bit unsigned integer, but does fit in a positive C int, it is silently truncated to 16-bit unsigned integer. However, this silent truncation feature is deprecated, and will raise an exception in future versions of Python.
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.
Next page: gevent.ssl
– Secure Sockets Layer (SSL/TLS) module