Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/webbit/webbit
A Java event based WebSocket and HTTP server
https://github.com/webbit/webbit
Last synced: 4 months ago
JSON representation
A Java event based WebSocket and HTTP server
- Host: GitHub
- URL: https://github.com/webbit/webbit
- Owner: webbit
- License: other
- Created: 2011-01-16T22:49:46.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2023-12-17T03:24:41.000Z (about 1 year ago)
- Last Synced: 2024-09-19T17:18:47.394Z (5 months ago)
- Language: Java
- Homepage: http://webbitserver.org/
- Size: 19.1 MB
- Stars: 816
- Watchers: 78
- Forks: 185
- Open Issues: 47
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
# Webbit - A Java event based WebSocket and HTTP server
[](http://travis-ci.org/webbit/webbit)
## Getting it
Prebuilt JARs are available from the [central Maven repository](http://search.maven.org/#search%7Cga%7C1%7Cwebbit) or the [Sonatype Maven repository](https://oss.sonatype.org/content/repositories/releases/org/webbitserver/webbit/).
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:
```java
WebServer webServer = WebServers.createWebServer(8080)
.add(new StaticFileHandler("/web")) // path to web content
.start()
.get();
```That was easy.
Now let's build a WebSocketHandler.
```java
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
Send
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); };
```
## Contributing
### Running JUnit tests
mvn clean test
or
make clean test
### Running Autobahn tests
[Autobahn](http://www.tavendo.de/autobahn) is a WebSocket server implemented in Python that comes with an extensive
[test suite](http://www.tavendo.de/autobahn/testsuite.html) 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
+ [Docs on wiki](https://github.com/webbit/webbit/wiki)
+ [Webbit mailing list](http://groups.google.com/group/webbit)
+ [@webbitserver](http://twitter.com/webbitserver) on Twitter
+ A [web based chat room](https://github.com/webbit/webbit/tree/master/src/test/java/samples/chatroom) is available in the samples directory. To try it out: 'make chatroom'
+ Jay Fields has written a [WebSockets with Clojure introduction](http://blog.jayfields.com/2011/02/clojure-web-socket-introduction.html) that uses Webbit