gevent._socket2 – Python 2 socket module

create_connection(address, timeout=<object object>, source_address=None)

Connect to address and return the 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.

class socket(family=2, type=1, proto=0, _sock=None)

Bases: object

closed
family

the socket family

proto

the socket protocol

ref
type

the socket type

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]])

fileno() → integer

Return the integer file descriptor of the socket.

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.

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.

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.

accept()
close(_closedsocket=<class 'gevent._socket2._closedsocket'>, cancel_wait_ex=error(9, 'File descriptor was closed in another greenlet'))
connect(address)
connect_ex(address)
dup() → socket object

Return a new socket object connected to the same system resource. Note, that the new socket does not inherit the timeout.

makefile(mode='r', bufsize=-1)
recv(*args)
recvfrom(*args)
recvfrom_into(*args)
recv_into(*args)
send(data, flags=0, timeout=<object object>)
sendall(data, flags=0)
sendto(*args)
setblocking(flag)
settimeout(howlong)
gettimeout()
shutdown(how)
SocketType

alias of socket

fromfd(*args)
socketpair(*args)
getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0)

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.

gethostbyname(host) → address

Return the IP address (a string of the form ‘255.255.255.255’) for a host.

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. Resolve host and port into list of address info entries.

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.

getnameinfo(sockaddr, flags) -> (host, port)

Get host and port for a sockaddr.

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 from gethostname() is returned.

ssl(sock, keyfile=None, certfile=None)

Next page: gevent.ssl – Secure Sockets Layer (SSL/TLS) module