Forma saysWebSockets open a persistent, two-way channel so client and server can message each other in real time.
For true bidirectional, low-latency communication — chat, multiplayer, live trading — use a WebSocket. new WebSocket('wss://…') upgrades from HTTP to a persistent socket; both sides then send() and receive via onmessage at any time.
Unlike SSE, it's full-duplex and can carry binary. You manage reconnection yourself, and it needs a WebSocket server, so it can't run in this offline sandbox — but the client API is tiny.
Power-ups you unlock
new WebSocket("wss://…") = persistent two-way channel
Both sides send() and receive via onmessage anytime
Full-duplex; supports binary; lower overhead than polling
You handle reconnection; needs a WS server
Captain Invalid Input attacks — common mistakes
Using ws:// on an https page (mixed content is blocked — use wss://)
No reconnect logic → silent death on a dropped connection
Choosing WebSockets when one-way SSE or plain fetch suffices
Boss battleWrite the client shape: open a socket, send a hello on open, log messages, and reconnect on close. (Point it at a real wss:// echo server to test.)