New in 2.4: Test runs you can trust See what's new →

A free WebSocket echo server for testing

An echo server and a push ticker, with the close codes and a small test.

Examples last run against the API on

A free WebSocket echo server for testing is at wss://api.testingapis.com/ws/echo. It sends a welcome message when you connect, then returns every text or binary message unchanged. It needs no key and no sign-up. A second endpoint, wss://api.testingapis.com/ws/ticker, pushes a fake stock price every second, so you can test a client that only listens. Everything below was run on 1 November 2026.

Try it here

Connect, send a message and watch it come back.

Messages appear here.

From a browser

Paste this into the browser console. The first message is the JSON welcome, so a client that expects only echoes has to skip it.

JavaScript
const socket = new WebSocket("wss://api.testingapis.com/ws/echo");

socket.onopen = () => socket.send("hello");
socket.onmessage = (event) => console.log(event.data);
socket.onclose = (event) => console.log(event.code, event.reason);

// {"type":"welcome","message":"Connected to TestingAPIs echo. Every text/binary message is echoed back. ..."}
// hello

From a terminal

Terminal
$ npx wscat -c wss://api.testingapis.com/ws/echo -x hello -w 2
{"type":"welcome","message":"Connected to TestingAPIs echo. Every text/binary message is echoed back. Send \u0022close\u0022 to disconnect."}
hello

A plain HTTP request to the same URL gets a 400, because the server only accepts a WebSocket upgrade.

What the server does

You sendThe server does
TextReturns it unchanged
BinaryReturns the same bytes as a binary message
closeCloses with code 1000, reason Bye!
A message over 64KBCloses with code 1009, reason Message exceeds 64KB

The two close cases give you a clean close and an error close to test without any setup, so your client's reconnect logic can tell them apart.

A server that pushes

The ticker sends one JSON message a second without you sending anything. Use it for rendering live updates and for checking that your client cleans up when the page closes.

JavaScript
const socket = new WebSocket("wss://api.testingapis.com/ws/ticker");
socket.onmessage = (event) => console.log(JSON.parse(event.data));

// {"type":"tick","data":{"tick":1,"symbol":"AAPL","name":"Apple Inc.","price":230.19,"change":2.67, ...}}
// {"type":"tick","data":{"tick":2,"symbol":"MSFT","name":"Microsoft Corp.","price":444.51,"change":6.40, ...}}

Messages appear here.

A small automated test

This checks the welcome, the echo and the close code, and exits with an error if any of them is wrong.

JavaScript
// Node.js 22 or later has WebSocket built in.
import assert from "node:assert/strict";

const socket = new WebSocket("wss://api.testingapis.com/ws/echo");
const replies = [];

await new Promise((resolve, reject) => {
  socket.onmessage = (event) => {
    replies.push(event.data);
    if (replies.length === 1) socket.send("hello");
    if (replies.length === 2) socket.send("close");
  };
  socket.onclose = (event) => {
    assert.equal(event.code, 1000);
    resolve();
  };
  socket.onerror = reject;
});

assert.equal(JSON.parse(replies[0]).type, "welcome");
assert.equal(replies[1], "hello");

The WebSocket testing tutorial covers reconnects, heartbeats and load in eight lessons, and the WebSocket reference lists both endpoints.