v154 · websocket options

Both forms, one server

Real connections to a same-origin echo endpoint, opened three ways. The server sends back what it was offered and what it chose, so each row is confirmed from both ends — not inferred from the client object alone.

Open three sockets

The endpoint is /public/echo-socket, served by this site. It knows echo.v2, echo, chat and soap, and picks the first of those the client offered — so the result depends on what you type above.

What each construction produced
constructionopened?client protocolserver saw offeredserver chose
Not run yet.
Press Connect.

code path

const url = "/public/echo-socket";   // resolved against this origin

new WebSocket(url, "chat");                      // a single string
new WebSocket(url, ["chat", "echo"]);            // a sequence
new WebSocket(url, { protocols: ["chat", "echo"] });   // Chrome 154

// All three send the same Sec-WebSocket-Protocol header, which is why
// the server's view of them is identical.

see also