Skip to content

murts42/java-web-socket-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Web Socket Server

A crappy and unmaintained implementation of a Web Socket Server in Java.


Usage

Yout need a custom ConnectionHandler that implements WebSocketConnectionHandler.

public class EchoConnectionHandler implements WebSocketCOnnectionHandler {

    private Vector<WebSocketConnection> connections = new Vector<WebSocketConnection>();

    @Override
    public void addConnection(WebSocketConnection connection) {
        connections.add(connection);
    }

    @Override
    public void processMessage(WebSocketConnection connection, String message) {
        connection.send(message); // echo the incoming message
    }

    @Override
    public void processClose(WebSocketConnection connection) {
        connections.remove(connection);
    }
}

Then you need to instantiate a WebSocketServer with the handler from above. The constructor automatically starts a background thread (which is probably bad design) which listens to incoming connections. It creates WebSocketConnectionsfor each new connections and hands them over to the handler.

Crappiness

This thing basically does not care how the initial handshake from the client looks, as long as it starts with GET, ends with \r\n\r\n and contains the Sec-WebSocket-Key header. It also does not support custom protocols and Secure Web Socket (wss://).

About

Crappy, old and unmaintained websocket Server in java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages