Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Java event based WebSocket and HTTP server
Java Python JavaScript

This branch is 719 commits behind webbit:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
src
.gitignore
Makefile
README.md

README.md

Webbit - A Java event based WebSocket and HTTP server

Quick start

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

WebServer webServer = WebServers.createWebServer(8080)
  .staticResources("/path/to/files")
  .start();

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");
    connectionCount++;
  }

  public void onClose(WebSocketConnection connection) {
    connectionCount--;
  }

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

  public static void main(String args) {
    WebServer webServer = WebServers.createWebServer(8080)
      .add("/hellowebsocket", new HelloWebSockets())
      .staticResources("/path/to/files")
      .start();
  }
}
Something went wrong with that request. Please try again.