Pikkola WebSocket, tool No. 77

A socket you can watch.

Type the address of a WebSocket or an EventSource, press connect, and every frame that crosses is listed with its direction, its size and the millisecond it arrived. When there is no server to point at, the same bench runs one inside the tab, so a payload can be built and tried before it is pointed at anything real.

3
transports
500
frames kept
0
uploads

The bench

One connection, every frame

Everything on this page is a frame: the handshake, the message you send, the one that comes back and the ping that keeps it open. The list is the connection, in order, with the number that decides whether it works.

What to open

A browser cannot set headers on a WebSocket and cannot skip the CORS check on an EventSource.

The connection idle
Frames
0
Sent
0
Received
0
Bytes out
0
Bytes in
0
Round trip
-
Last event
-

    Nothing yet. Connect to an address, or press Simulate a server and send a frame.

    What is on the wire, in order

    A socket is not a request. It opens once, stays open, and every message shares that one connection, which is why the list and its timestamps are the useful artefact rather than a final response.

    01

    Open, then send

    The handshake is an HTTP upgrade with a key the server answers with a hash. The browser does all of it and reports only open or error, so the page records the moment the socket opened and the subprotocol the server agreed to, and nothing invented about the handshake itself.

    02

    Every frame, both ways

    A sent frame and a received frame are recorded the same way: direction, kind, byte length, time to the millisecond and the payload up to 4000 characters. Binary frames are counted in bytes and shown as hex, because guessing an encoding is how a binary protocol gets misread.

    03

    A server in the tab

    The simulated server echoes what it is sent, answers {"type":"ping"} with a pong, and sends a heartbeat every five seconds. It exists so a payload, a filter and an export can be tried with no network at all, and it says so in every row it writes.

    What the browser decides for you

    Half of a socket tester's surprises are not the server's. They are the four things a browser will not let a page do with a socket, and this page reports them instead of pretending otherwise.

    Part of the socket What this page does What it cannot do
    The handshake Records the open event, the URL and the subprotocol Set headers, cookies of its own, or an origin the server did not allow
    Binary frames Counts the bytes and shows them as hex Guess an encoding, or decode a compressed frame
    Ping and pong Sends an application-level ping and measures the answer Send a protocol-level ping frame: the browser answers those itself
    Close codes Shows the code and the reason the server sent Choose a close code other than the normal one
    EventSource reconnects Shows each reconnect as a new open, with the attempt count Change the retry delay: the server's retry field owns it
    TLS Refuses a ws:// address from this https page and says why Connect in plain text from a secure page: the browser blocks it

    The list keeps the last 500 frames. Export before closing the tab: nothing is written to storage, so a reload is a new connection with an empty list.

    Field guide

    Reading a socket without guessing

    A socket test is a sequence, not a result. The handshake opens, the first frame carries the token, a ping keeps the middle alive and a close code tells you who ended it. This is the order worth reading them in, and the places where a browser decides the answer before the server does.

    The handshake is an HTTP request you cannot see

    A WebSocket starts as an HTTP/1.1 request with Upgrade: websocket and a random Sec-WebSocket-Key. The server answers 101 and returns the SHA-1 of that key joined to a constant, which proves it understood the upgrade rather than repeating a cached response. The browser builds that request for you and never shows it, so the useful facts are the ones it does expose: whether the socket opened, how long it took, and which subprotocol the server picked. A server that insists on a subprotocol will fail the whole connection when the client sends none, which looks like a network error and is not one.

    The same request carries cookies for the target host. That is why a socket endpoint with no origin check is a cross-site scripting hole rather than a convenience: another site's page can open your socket with the visitor's cookie attached. When a socket works in curl and fails in the browser, the origin check is usually the reason, and the browser console is where it is named.

    Frames, close codes and the number in between

    Every message is a frame with an opcode. Text and binary are the two a page can send; ping, pong and close are handled by the browser, which is why a protocol-level ping does not appear in this timeline. A close frame carries a code and an optional reason: 1000 is deliberate, 1001 means the page is going away, 1006 is never sent by anyone and instead means the connection died without a close frame, and 1011 is the server saying its own handler threw. When a server drops a socket in the middle of a message, the browser reports 1006 and there is no reason string to read, because there was no frame to carry one.

    The gap between two frames is often the interesting number. A heartbeat every 30 seconds is a server keeping a load balancer's idle timer from closing the socket; a heartbeat every 200 milliseconds is a server with nothing to send and a loop that should be a timer. A round trip that climbs slowly is congestion or a proxy; one that jumps to exactly a round number is usually a proxy timeout being swallowed and reopened.

    Keepalive is an application decision

    The protocol has ping frames, and browsers answer them without waking the page. What a page usually needs instead is an application-level message that says "still here", because the thing that times out is not the socket but a proxy, a load balancer or a mobile network's NAT table. Fifteen to thirty seconds is the usual range; anything faster is traffic the server pays for. This page's keepalive sends the same frame you would send by hand, records each one in the timeline, and stops when the socket closes.

    EventSource is a different animal

    An EventSource is a plain HTTP GET with Accept: text/event-stream that the server keeps open, writing lines. It reconnects by itself, with a delay the server can set with a retry: line, and it reports each attempt through the open event. It cannot send anything: there is no write side at all, which is why a chat or a cursor needs a WebSocket. The browser applies CORS to it as it would to any fetch, so a server that streams happily to its own page will refuse a request from another origin unless it says otherwise. When an EventSource fails without a message, that is CORS, and the console has the sentence the timeline cannot show.

    What this bench does with a failure

    Nothing is retried behind your back. A failed connection is written into the timeline as an error row with the time, the address and whatever the browser was willing to say, and the socket is left closed until you press connect again. A close is written with its code and reason, and the state pill returns to closed rather than idle, because those are different states and a tester that hides the difference is a tester that makes you guess. The last 500 frames stay in memory only: reload and the list is empty, which is why the export button exists.

    For the request before the upgrade, Pikkola HTTP reads a whole exchange. When the token in that first frame has to be checked, Pikkola JWT decodes it and says what it proves.

    Questions

    Do my messages go anywhere besides the address I type?

    No. The page opens the socket you name and writes the frames you send into it. There is no relay in the middle, no account and no log: the only other request the page makes is the cookieless page-view count. The exception is the simulated server, which never opens a socket at all.

    Why can I not add an Authorization header?

    Because the browser's WebSocket API has no parameter for headers, and that is a browser rule rather than a limit of this page. A token has to travel in the URL, in the first message after the socket opens, or through a cookie the server already set. A tester that offers a header box is offering something a browser will silently drop.

    What is the simulated server for?

    For the part of the work that needs no server: building a payload, checking that the JSON is valid, seeing how the filter reads a timeline and what an export file looks like. It echoes what it is sent, answers a ping, and sends a heartbeat every five seconds. Every row it writes is marked simulated.

    Why does an EventSource to another site fail with no message?

    An EventSource is a plain HTTP request, so the browser applies CORS: the server has to answer with Access-Control-Allow-Origin for this page's origin, and a failure is reported to the page as a bare error with no reason, by design. The browser console names the real cause; the timeline records the error and the attempt number.

    Can I test a socket that needs a cookie from another site?

    Only if that cookie is already set on this browser for that host, and the server accepts the page's origin. Opening the site in another tab first sometimes does it. A WebSocket handshake does send cookies for its own host, which is one reason a cross-site socket without a cookie check is a security problem on the server side rather than a testing convenience.