Skip to main content

Transports: WebSocket and CongSocket

An IOSignal server accepts two kinds of connection. Whichever one a client uses, the message format, tags, channels and authentication are the same, and clients on both exchange messages through the same server. A browser on WebSocket and an Arduino board on CongSocket share one channel.

WebSocketCongSocket
Addressws://host:port, wss://host/wscong://host:port
Server portport (public broker: wss://io.iosignal.net/ws, 443)congPort (public broker: io.iosignal.net:55488)
Built onWebSocket frames after an HTTP upgradeLength-prefixed frames on TCP
On connectingOne HTTP request and response (a few hundred bytes, depending on headers)Nothing: once TCP is open, the server sends its hello (13 bytes)
Header per messageServer to client 2, 4 or 10 bytes. Client to server adds a 4-byte mask, and every byte sent is XORed with it2 bytes up to 255 bytes, 3 bytes up to 64 KiB, 4 or 5 bytes above
Encryptionwss:// uses TLS. Logged in over ws://: Boho ENCLogged in: Boho ENC

Support by client​

ClientWebSocketCongSocket
Browser✅—
Node.js✅ IO✅ IOCongSocket
Arduino—✅
Python✅✅
MicroPython boards—✅
Android (Kotlin)✅—

How to open both ports on a server is in running a server.

Why CongSocket​

  • It is light. No HTTP handling, no masking, no TLS library. The default receive buffer of the Arduino IOSignal library is 80 bytes, and even an Arduino Uno with 2 KB of RAM can connect over Ethernet.
  • It is encrypted without TLS. Logged in with a device key, the connection is encrypted with Boho ENC and every packet is checked against forgery. No certificates or certificate store are needed. The board's clock must be within 60 seconds of the server's (Arduino takes it from the server's hello; MicroPython sets it with ntptime). Authentication
  • It connects fast. No HTTP upgrade and no TLS handshake: once TCP is open, the login and the CID request follow.
  • It follows the server's directions. When a switcher names another broker by IPv4 address and port (7 bytes), the client moves there. Connection and CID lifecycle

Measured: ESP32-C3​

Measured on an ESP32-C3 (no PSRAM) running MicroPython 1.29 with the Python package. Memory per connection:

ConnectionPython heapESP-IDF heapTotal
cong:// anonymous0.35 kB0.36 kBabout 0.7 kB
cong:// logged in (Boho 2.x ENC_488, 9.x)0.88 kB0.24 kBabout 1.1 kB
TLS socket (below wss://)33 kB31 kBabout 64 kB

The board started with about 177 kB of Python heap and 102 kB of ESP-IDF heap free. The TLS handshake took 0.68 s. In code size, the CongSocket module is 0.9 kB and a WebSocket client for MicroPython (micropython-lib aiohttp) is 7.5 kB.

Echo round trip through a server on the same router, from the same board (average of 10):

SizeAnonymousLogged in (ENC_488 both ways, 9.x)
32 B8.3 ms16.8 ms
256 B9.1 ms21.5 ms
1 KB11.2 ms43.5 ms

Things to know​

  • Anonymous connections are plain text. CongSocket and ws:// encrypt nothing without a login. Send values others must not see from a logged-in connection, or as E2E signals.
  • Large data can be slow to encrypt. The values above were measured with 9.x (Boho 2.x, one SHA-256 per 32 bytes); Ascon in 10.0.0 has not been measured on the board yet. With 9.x, the Python implementation on the ESP32-C3 above took 30 ms to seal and open 1 KB and 108 ms for 4 KB, while the chip's hardware AES took 1.7 ms for 4 KB. Short commands and states are fine; for a board that often sends large data such as photos or files, take the difference into account.
  • Firewalls: networks such as offices often block everything but 443. Where the CongSocket port (55488) is blocked, a board cannot reach the server. Use wss:// on computers and servers.
  • ENC is symmetric encryption with the device key. The server knows the key too, so it can read the content. When the server must not read it, use E2E signals.

Which to choose​

  • Browsers: WebSocket only. Use wss:// on public servers.
  • Node.js and Python on computers and servers: usually wss://. For a light connection to a server on the same router, cong:// works too.
  • Arduino and MicroPython boards: cong://, logged in for encryption.