webbit

A Java event based WebSocket and HTTP server

License

License

GroupId

GroupId

org.webbitserver
ArtifactId

ArtifactId

webbit
Last Version

Last Version

0.4.15
Release Date

Release Date

Type

Type

jar
Description

Description

webbit
A Java event based WebSocket and HTTP server
Project URL

Project URL

http://webbitserver.org/

Download webbit

How to add to project

<!-- https://jarcasting.com/artifacts/org.webbitserver/webbit/ -->
<dependency>
    <groupId>org.webbitserver</groupId>
    <artifactId>webbit</artifactId>
    <version>0.4.15</version>
</dependency>
// https://jarcasting.com/artifacts/org.webbitserver/webbit/
implementation 'org.webbitserver:webbit:0.4.15'
// https://jarcasting.com/artifacts/org.webbitserver/webbit/
implementation ("org.webbitserver:webbit:0.4.15")
'org.webbitserver:webbit:jar:0.4.15'
<dependency org="org.webbitserver" name="webbit" rev="0.4.15">
  <artifact name="webbit" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webbitserver', module='webbit', version='0.4.15')
)
libraryDependencies += "org.webbitserver" % "webbit" % "0.4.15"
[org.webbitserver/webbit "0.4.15"]

Dependencies

compile (1)

Group / Artifact Type Version
io.netty : netty jar 3.5.5.Final

test (3)

Group / Artifact Type Version
junit : junit jar 4.10
org.mockito : mockito-all jar 1.9.0
com.google.code.gson : gson jar 1.7.2

Project Modules

There are no modules declared in this project.

Webbit - A Java event based WebSocket and HTTP server

Build Status

Getting it

Prebuilt JARs are available from the central Maven repository or the Sonatype Maven repository.

Alternatively, you can get the latest code from Git and build it yourself:

git clone git://github.com/webbit/webbit.git
cd webbit

Make

Build is done with make. On OS-X and Linux this should work out of the box. On Solaris, use gmake. On Windows you will need Cygwin.

make

Maven

mvn install

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
            .start()
            .get();

That was easy.

Now let's build a WebSocketHandler.

public class HelloWebSockets extends BaseWebSocketHandler {
    private 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())
                .add(new StaticFileHandler("/web"));
        webServer.start();
        System.out.println("Server running at " + webServer.getUri());
    }
}

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

<html>
  <body>

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

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

    <script>
      function showMessage(text) {
        document.getElementById('message').innerHTML = text;
      }

      var ws = new WebSocket('ws://' + document.location.host + '/hellowebsocket');
      showMessage('Connecting...');
      ws.onopen = function() { showMessage('Connected!'); };
      ws.onclose = function() { showMessage('Lost connection'); };
      ws.onmessage = function(msg) { showMessage(msg.data); };
    </script>
  </body>
</html>

Contributing

Running JUnit tests

mvn clean test

or

make clean test

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

Running Autobahn tests

In shell A:

make echo

In shell B:

make autobahn

Open reports/servers/index.html to see the results.

More

Versions

Version
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.3
0.4.2
0.4.0
0.3.8
0.3.7
0.3.6
0.3.4
0.3.3
0.3.2
0.3.0
0.2.16
0.2.14
0.2.13
0.2.12
0.2.10
0.2.9
0.2.8
0.2.2
0.2.1
0.2.0
0.1.17
0.1.16
0.1.13
0.1.12
0.1.11
0.1.10