Skip to content
Browse files

Added a webbit implementation

  • Loading branch information...
1 parent 6c35e40 commit 10ff81307870a79fde7c5e2c19ffe6b4d24d0657 @ericmoritz committed Jun 13, 2012
View
51 competition/EchoWsServer.java
@@ -0,0 +1,51 @@
+import org.webbitserver.BaseWebSocketHandler;
+import org.webbitserver.WebServer;
+import org.webbitserver.WebSocketConnection;
+import org.webbitserver.handler.HttpToWebSocketHandler;
+import org.webbitserver.handler.exceptions.PrintStackTraceExceptionHandler;
+import org.webbitserver.netty.NettyWebServer;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.concurrent.ExecutionException;
+
+public class EchoWsServer {
+
+ private final WebServer webServer;
+
+ public EchoWsServer(WebServer webServer) throws IOException {
+ this.webServer = webServer;
+ webServer.add(new HttpToWebSocketHandler(new EchoHandler())).connectionExceptionHandler(new PrintStackTraceExceptionHandler());
+ }
+
+ public void start() throws ExecutionException, InterruptedException {
+ webServer.start().get();
+ }
+
+ public URI uri() throws IOException {
+ return webServer.getUri();
+ }
+
+ public void stop() throws ExecutionException, InterruptedException {
+ webServer.stop().get();
+ }
+
+ private static class EchoHandler extends BaseWebSocketHandler {
+ @Override
+ public void onMessage(WebSocketConnection connection, String msg) throws Exception {
+ connection.send(msg);
+ }
+
+ @Override
+ public void onMessage(WebSocketConnection connection, byte[] msg) {
+ connection.send(msg);
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ EchoWsServer server = new EchoWsServer(new NettyWebServer(8000));
+ server.start();
+ System.out.println("Echo server running on: " + server.uri());
+ }
+
+}
View
5 competition/Makefile
@@ -0,0 +1,5 @@
+build:
+ javac -cp webbit-0.4.7-full.jar EchoWsServer.java
+
+clean:
+ rm *.class
View
BIN competition/webbit-0.4.7-full.jar
Binary file not shown.
View
1 competition/wsdemo-java.sh
@@ -0,0 +1 @@
+java -cp webbit-0.4.7-full.jar:./ EchoWsServer

0 comments on commit 10ff813

Please sign in to comment.
Something went wrong with that request. Please try again.