socketpool
¶
The socketpool
module provides sockets through a pool. The pools themselves
act like CPython’s socket
module.
Available on these boards
- class socketpool.Socket¶
TCP, UDP and RAW socket. Cannot be created directly. Instead, call
SocketPool.socket()
.Provides a subset of CPython’s
socket.socket
API. It only implements the versions of recv that do not allocate bytes objects.- __exit__() None ¶
Automatically closes the Socket when exiting a context. See Lifetime and ContextManagers for more info.
- accept() Tuple[Socket, Tuple[str, int]] ¶
Accept a connection on a listening socket of type SOCK_STREAM, creating a new socket of type SOCK_STREAM. Returns a tuple of (new_socket, remote_address)
- bind(address: Tuple[str, int]) None ¶
Bind a socket to an address
- Paramètres:
address (~tuple) – tuple of (remote_address, remote_port)
- connect(address: Tuple[str, int]) None ¶
Connect a socket to a remote address
- Paramètres:
address (~tuple) – tuple of (remote_address, remote_port)
- listen(backlog: int) None ¶
Set socket to listen for incoming connections
- Paramètres:
backlog (~int) – length of backlog queue for waiting connetions
- recvfrom_into(buffer: _typing.WriteableBuffer) Tuple[int, Tuple[str, int]] ¶
Reads some bytes from a remote address.
Returns a tuple containing * the number of bytes received into the given buffer * a remote_address, which is a tuple of ip address and port number
- Paramètres:
buffer (object) – buffer to read into
- recv_into(buffer: _typing.WriteableBuffer, bufsize: int) int ¶
Reads some bytes from the connected remote address, writing into the provided buffer. If bufsize <= len(buffer) is given, a maximum of bufsize bytes will be read into the buffer. If no valid value is given for bufsize, the default is the length of the given buffer.
Suits sockets of type SOCK_STREAM Returns an int of number of bytes read.
- send(bytes: _typing.ReadableBuffer) int ¶
Send some bytes to the connected remote address. Suits sockets of type SOCK_STREAM
- Paramètres:
bytes (~bytes) – some bytes to send
- sendto(bytes: _typing.ReadableBuffer, address: Tuple[str, int]) int ¶
Send some bytes to a specific address. Suits sockets of type SOCK_DGRAM
- Paramètres:
bytes (~bytes) – some bytes to send
address (~tuple) – tuple of (remote_address, remote_port)
- setblocking(flag: bool) int | None ¶
Set the blocking behaviour of this socket.
- Paramètres:
flag (~bool) – False means non-blocking, True means block indefinitely.
- class socketpool.SocketPool¶
A pool of socket resources available for the given radio. Only one SocketPool can be created for each radio.
SocketPool should be used in place of CPython’s socket which provides a pool of sockets provided by the underlying OS.
- AF_INET :int¶
- AF_INET6 :int¶
- SOCK_STREAM :int¶
- SOCK_DGRAM :int¶
- SOCK_RAW :int¶
- socketpool.getaddrinfo(host: str, port: int, family: int = 0, type: int = 0, proto: int = 0, flags: int = 0) Tuple[int, int, int, str, Tuple[str, int]] ¶
Gets the address information for a hostname and port
Returns the appropriate family, socket type, socket protocol and address information to call socket.socket() and socket.connect() with, as a tuple.