ssl.socket
Prev: ssl.RAND_status | Up: ssl | Next: ssl.socket_error
Rel: ssl.AlertDescription, ssl.cert_time_to_seconds, ssl.CertificateError, ssl.create_connection
Ref: docs.python.org — ssl.socket
Tags: #public #python3 #stdlib #ssl
Import
import ssl
from ssl import socket
Signature & Overview
ssl.socket(family=-1, type=-1, proto=-1, fileno=None)
A subclass of _socket.socket adding the makefile() method.
Methods & Attributes
socket.accept(self)— Wait for an incoming connection. Return a new socket representing the connection, and the address of the client.socket.bind(self, object, /)— 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]]])socket.close(self)—socket.closemethod/property.socket.connect(self, object, /)— Connect the socket to a remote address. For IP sockets, the address is a pair (host, port).socket.connect_ex(self, object, /)— This is like connect(address), but returns an error code (the errno value) instead of raising an exception when an error occurs.socket.detach(self)— Close the socket object without closing the underlying file descriptor.socket.dup(self)— Duplicate the socket. Return a new socket object connected to the same system resource. The new socket is non-inheritable.socket.family(...)— Read-only access to the address family for this socket.socket.fileno(self, /)— Return the integer file descriptor of the socket.socket.get_inheritable(self)— Get the inheritable flag of the socketsocket.getblocking(self, /)— Returns True if socket is in blocking mode, or False if it is in non-blocking mode.socket.getpeername(self, /)— Return the address of the remote endpoint. For IP sockets, the address info is a pair (hostaddr, port).socket.getsockname(self, /)— 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). For IPv6 sockets, the address info is a 4-tuplesocket.getsockopt(...)— Get a socket option. See the Unix manual for level and option.socket.gettimeout(self, /)— Returns the timeout in seconds (float) associated with socket operations. A timeout of None indicates that timeouts on socket operations are disabled.socket.listen(...)— 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 newsocket.makefile(self, mode='r', buffering=None, *, encoding=None, errors=None, newline=None)— The arguments are as for io.open() after the filename, except the only supported mode values are 'r' (default), 'w', 'b', or a combination of those.socket.recv(...)— 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. Whensocket.recv_into(...)— 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.socket.recvfrom(...)— Like recv(buffersize, flags) but also return the sender's address info.socket.recvfrom_into(...)— Like recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info.socket.recvmsg(...)— Receive normal data (up to bufsize bytes) and ancillary data from the socket. The ancbufsize argument sets the size in bytes of the internal buffer used to receive the ancillary data; it defaults to 0,socket.recvmsg_into(...)— Receive normal data and ancillary data from the socket, scattering the non-ancillary data into a series of buffers. The buffers argument must be an iterable of objects that export writable bufferssocket.send(...)— 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.socket.sendall(...)— 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 impossiblesocket.sendfile(self, file, offset=0, count=None)— Send a file until EOF is reached by using high-performance os.sendfile() and return the total number of bytes which were sent.socket.sendmsg(...)— Send normal and ancillary data to the socket, gathering the non-ancillary data from a series of buffers and concatenating it into a single message. The buffers argument specifies the non-ancillarysocket.sendto(...)— Like send(data, flags) but allows specifying the destination address.socket.set_inheritable(self, inheritable)— Set the inheritable flag of the socketsocket.setblocking(self, object, /)— Set the socket to blocking (flag is true) or non-blocking (false).socket.setsockopt(...)— setsockopt(level, option, value: buffer) setsockopt(level, option, None, optlen: int) Set a socket option. See the Unix manual for level and option.socket.settimeout(self, object, /)— 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).socket.shutdown(self, object, /)— 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).socket.type(...)— Read-only access to the socket type.
Usage
import socket as _socket
import ssl
assert ssl.socket is _socket.socket
Gotchas
- Re-export of
socket.socket: Always importsocketfrom thesocketmodule directly.
REPL Inspect
from ssl import socket
help(socket)
Linked from
Related notes
- tuts/python3/stdlib_module/ssl/RAND_status Linked here; links to this page; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/socket_error Linked here; links to this page; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ssl/AlertDescription Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/cert_time_to_seconds Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/CertificateError Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/create_connection Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/create_default_context shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/DefaultVerifyPaths shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/DER_cert_to_PEM_cert shared tags: #ssl, #stdlib