The socketpool module provides sockets through a pool. The pools themselves act like CPython’s socket module.

For more information about the socket module, see the CPython documentation:

Available on these boards
  • AITHinker ESP32-C3S_Kit
  • AITHinker ESP32-C3S_Kit_2M
  • ATMegaZero ESP32-S2
  • Adafruit Camera
  • Adafruit Feather ESP32-S2 TFT
  • Adafruit Feather ESP32S2
  • Adafruit Feather ESP32S3 No PSRAM
  • Adafruit FunHouse
  • Adafruit MagTag
  • Adafruit Metro ESP32S2
  • Adafruit QT Py ESP32-S3 no psram
  • Adafruit QT Py ESP32C3
  • Adafruit QT Py ESP32S2
  • Artisense Reference Design RD00
  • BastWiFi
  • CrumpS2
  • Cytron Maker Feather AIoT S3
  • ESP 12k NodeMCU
  • ESP32-C3-DevKitM-1
  • ESP32-S2-DevKitC-1-N4
  • ESP32-S2-DevKitC-1-N4R2
  • ESP32-S3-Box-2.5
  • ESP32-S3-DevKitC-1-N8
  • ESP32-S3-DevKitC-1-N8R2
  • ESP32-S3-DevKitC-1-N8R8
  • ESP32-S3-DevKitM-1-N8
  • ESP32-S3-USB-OTG-N8
  • Feather ESP32S2 without PSRAM
  • FeatherS2
  • FeatherS2 Neo
  • FeatherS2 PreRelease
  • FeatherS3
  • Franzininho WIFI w/Wroom
  • Franzininho WIFI w/Wrover
  • Gravitech Cucumber M
  • Gravitech Cucumber MS
  • Gravitech Cucumber R
  • Gravitech Cucumber RS
  • HMI-DevKit-1.1
  • HexKyS2
  • IoTs2
  • Kaluga 1
  • LILYGO TTGO T8 ESP32-S2 w/Display
  • MORPHEANS MorphESP-240
  • MicroDev microC3
  • MicroDev microS2
  • Oak Dev Tech PixelWing ESP32S2
  • ProS3
  • S2Mini
  • S2Pico
  • Saola 1 w/Wroom
  • Saola 1 w/Wrover
  • Targett Module Clip w/Wroom
  • Targett Module Clip w/Wrover
  • TinyS2
  • TinyS3
  • nanoESP32-S2 w/Wrover
  • nanoESP32-S2 w/Wroom

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.

__hash__() int

Returns a hash for the Socket.

__enter__() Socket

No-op used by Context Managers.

__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


address (~tuple) – tuple of (remote_address, remote_port)

close() None

Closes this Socket and makes its resources available to its SocketPool.

connect(address: Tuple[str, int]) None

Connect a socket to a remote address


address (~tuple) – tuple of (remote_address, remote_port)

listen(backlog: int) None

Set socket to listen for incoming connections


backlog (~int) – length of backlog queue for waiting connetions

recvfrom_into(buffer: circuitpython_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


buffer (object) – buffer to read into

recv_into(buffer: circuitpython_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.

  • buffer (bytearray) – buffer to receive into

  • bufsize (int) – optionally, a maximum number of bytes to read.

send(bytes: circuitpython_typing.ReadableBuffer) int

Send some bytes to the connected remote address. Suits sockets of type SOCK_STREAM


bytes (~bytes) – some bytes to send

sendto(bytes: circuitpython_typing.ReadableBuffer, address: Tuple[str, int]) int

Send some bytes to a specific address. Suits sockets of type SOCK_DGRAM

  • bytes (~bytes) – some bytes to send

  • address (~tuple) – tuple of (remote_address, remote_port)

setblocking(flag: bool) Optional[int]

Set the blocking behaviour of this socket.


flag (~bool) – False means non-blocking, True means block indefinitely.

settimeout(value: int) None

Set the timeout value for this socket.


value (~int) – timeout in seconds. 0 means non-blocking. None 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
socket(family: int = AF_INET, type: int = SOCK_STREAM) Socket

Create a new socket

  • family (~int) – AF_INET or AF_INET6

  • type (~int) – SOCK_STREAM, SOCK_DGRAM or SOCK_RAW

The proto (protocol) and fileno arguments available in socket.socket() in CPython are not supported.

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.