Skip to main content

Networking

Kog apps talk to the network with the same globals you already know from the webfetch, WebSocket, WiFi, and a Kog-native socket API — available with no import:

const res = await fetch('https://api.example.com/status');
const status = await res.json();

No import { fetch }, no setup. The runtime installs these globals before your app runs, on every target: the ESP32 device, the desktop simulator, and the in-browser playground.

One surface, three targets

The API is identical everywhere; only what's underneath changes.

ESP32 deviceDesktop simulatorWeb playground
fetch / WebSocketnative HTTP/WS clienthost socketsthe browser's own (CORS applies)
TCPSocket / UDPSocket / TCPServerlwIPhost socketsnot available — throws a clear error
WiFireal joinalways-connected emulationalways-connected emulation

This means you can prototype a fetch-driven dashboard in the playground, run it in the simulator, and flash it to a board — no code changes.

Honest about the edges

Kog is a microcontroller runtime, not a browser, so the surface is narrowed to what native actually delivers. The narrowings are deliberate and documented: bodies are buffered (no ReadableStream), there's no Blob/FormData, sockets deliver ArrayBuffer, and Wi-Fi is emulated off-device. The full list is in the API reference divergences.

Two edges worth knowing up front:

  • CORS is real in the web playground. There, fetch and WebSocket are the browser's, so cross-origin calls obey the same-origin policy. On a device there is no CORS. See the fetch guide.
  • Raw sockets don't exist in a browser. TCPSocket/UDPSocket/TCPServer throw a helpful error in the playground; run them on a device or the desktop simulator.

Where to go next

  • fetch — HTTP requests, JSON, timeouts, errors, CORS.
  • WebSocket — live bidirectional streams.
  • Sockets — raw TCP/UDP and running a server on-device.
  • Wi-Fi — connecting, and baking credentials in at flash time.
  • API reference — every global, every method, every divergence.