WebSocket Echo Test

WebSocket Echo Test

Echo Test

The first section of this page will let you do an HTML5 WebSocket test against the echo server. The second section walks you through creating a WebSocket application yourself.

You can also inspect WebSocket messages using your browser.

Try it out!

This browser supports WebSocket.


Use secure WebSocket (TLS)
Connect Disconnect


Rock it with HTML5 WebSocket

Send Log:
Clear log


Press the Connect button.
Once connected, enter a message and press the Send button. The output will appear in the Log section. You can change the message and send again multiple times.
Press the Disconnect button.
Note: In some environments the WebSocket connection may fail due to intermediary firewalls, proxies, routers, etc. In that case take advantage of WebSocket’s secure capability and check Use secure WebSocket (TLS). Even if you have no issues you can still feel free to test using a secure connection.

Creating your own test

Using a text editor, copy the following code and save it as websocket.html somewhere on your hard drive. Then simply open it in a browser. The page will automatically connect, send a message, display the response, and close the connection.

  <!DOCTYPE html>
  <meta charset="utf-8" />
  <title>WebSocket Test</title>
  <script language="javascript" type="text/javascript">

  var wsUri = "ws://echo.websocket.org/";
  var output;

  function init()
    output = document.getElementById("output");

  function testWebSocket()
    websocket = new WebSocket(wsUri);
    websocket.onopen = function(evt) { onOpen(evt) };
    websocket.onclose = function(evt) { onClose(evt) };
    websocket.onmessage = function(evt) { onMessage(evt) };
    websocket.onerror = function(evt) { onError(evt) };

  function onOpen(evt)
    doSend("WebSocket rocks");

  function onClose(evt)

  function onMessage(evt)
    writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>');

  function onError(evt)
    writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);

  function doSend(message)
    writeToScreen("SENT: " + message);

  function writeToScreen(message)
    var pre = document.createElement("p");
    pre.style.wordWrap = "break-word";
    pre.innerHTML = message;

  window.addEventListener("load", init, false);


  <h2>WebSocket Test</h2>

  <div id="output"></div>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.