Skip to content
A Java event based WebSocket and HTTP server
Java Python JavaScript Other
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Webbit - A Java event based WebSocket and HTTP server

Getting it

Warning: Webbit has not had a stable release yet - the API changes regularly.

git clone git://
cd webbit

You will need to add dist/webbit.jar to your classpath - it has no external dependencies.

Quick start

Start a web server on port 8080 and serve some static files:

WebServer webServer = WebServers.createWebServer(8080)
  .add(new StaticFileHandler("/web")) // path to web content

That was easy.

Now let's build a WebSocketHandler.

public class HelloWebSockets implements WebSocketHandler {

  int connectionCount;

  public void onOpen(WebSocketConnection connection) {
    connection.send("Hello! There are " + connectionCount + " other connections active");

  public void onClose(WebSocketConnection connection) {

  public void onMessage(WebSocketConnection connection, String message) {
    connection.send(message.toUpperCase()); // echo back message in upper case

  public void onMessage(WebSocketConnection connection, byte[] message) {

  public void onPong(WebSocketConnection connection, String message) {

  public static void main(String[] args) {
    WebServer webServer = WebServers.createWebServer(8080)
      .add("/hellowebsocket", new HelloWebSockets())
      .add(new StaticFileHandler("/web"))
    System.out.println("Server running at " + webServer.getUri());

And a page that uses the WebSocket (web/index.html)


    <!-- Send text to websocket -->
    <input id="userInput" type="text">
    <button onclick="ws.send(document.getElementById('userInput').value)">Send</button>

    <!-- Results -->
    <div id="message"></div>

      function showMessage(text) {
        document.getElementById('message').innerHTML = text;

      var ws = new WebSocket('ws://' + + '/hellowebsocket');
      ws.onopen = function() { showMessage('Connected!'); };
      ws.onclose = function() { showMessage('Lost connection'); };
      ws.onmessage = function(msg) { showMessage(; };

Running Autobahn tests

Autobahn is a WebSocket server implemented in Python that comes with an extensive test suite that can be used to test other WebSocket servers as well.

We're using it to test Webbit.

Installing Autobahn

git submodule update --init
python --no-site-packages . # create local version of python (installing twisted)

Running Autobahn tests

In shell A:

make echo

In shell B:

make autobahn


Something went wrong with that request. Please try again.