On this page
socket.SocketType
Prev: socket.socketpair | Up: socket | Next: socket.timeout
Rel: socket.AddressFamily, socket.close, socket.create_connection, socket.create_server
Ref: docs.python.org — socket.SocketType
Tags: #public #python3 #stdlib #socket
Import
import socket
from socket import SocketType
Signature & Overview
socket.SocketType(...)
socket(family=-1, type=-1, proto=-1, fileno=None) -> socket object Open a socket of the given type. The family argument specifies the address family; it defaults to AF_INET. The type argument specifies
Methods & Attributes
SocketType.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]]])SocketType.close(self, /)— Close the socket. It cannot be used after this call.SocketType.connect(self, object, /)— Connect the socket to a remote address. For IP sockets, the address is a pair (host, port).SocketType.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.SocketType.detach(self, /)— Close the socket object without closing the underlying file descriptor.SocketType.fileno(self, /)— Return the integer file descriptor of the socket.SocketType.getblocking(self, /)— Returns True if socket is in blocking mode, or False if it is in non-blocking mode.SocketType.getpeername(self, /)— Return the address of the remote endpoint. For IP sockets, the address info is a pair (hostaddr, port).SocketType.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-tupleSocketType.getsockopt(...)— Get a socket option. See the Unix manual for level and option.SocketType.gettimeout(self, /)— Returns the timeout in seconds (float) associated with socket operations. A timeout of None indicates that timeouts on socket operations are disabled.SocketType.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 newSocketType.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. WhenSocketType.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.SocketType.recvfrom(...)— Like recv(buffersize, flags) but also return the sender's address info.SocketType.recvfrom_into(...)— Like recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info.SocketType.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,SocketType.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 buffersSocketType.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.SocketType.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 impossibleSocketType.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-ancillarySocketType.sendto(...)— Like send(data, flags) but allows specifying the destination address.SocketType.setblocking(self, object, /)— Set the socket to blocking (flag is true) or non-blocking (false).SocketType.setsockopt(...)— setsockopt(level, option, value: buffer) setsockopt(level, option, None, optlen: int) Set a socket option. See the Unix manual for level and option.SocketType.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).SocketType.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).
Usage
import socket
assert issubclass(socket.socket, socket.SocketType)
Gotchas
- Base C type (
_socket.socket):socket.socketis a Python subclass ofsocket.SocketType, so useisinstance(obj, socket.SocketType)orissubclass(socket.socket, socket.SocketType).
REPL Inspect
from socket import SocketType
help(SocketType)
Linked from
Related notes
- tuts/python3/stdlib_module/socket/socketpair Linked here; links to this page; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/timeout Linked here; links to this page; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/AddressFamily Linked here; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/close Linked here; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/create_connection Linked here; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/create_server Linked here; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/socket Linked here; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/socket/dup shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/error shared tags: #socket, #stdlib