This is a proof of concept implementation of a Websockify server in Java. The server acts as a bridge between WebSockets and TCP connections, allowing for bidirectional communication between WebSocket clients and TCP servers.
- WebSocket to TCP bridge:
- The server accepts WebSocket connections and forwards the received messages to a specified TCP server.
- TCP to WebSocket bridge:
- The server listens for incoming TCP connections and relays the received data to the WebSocket clients.
- noVNC (HTML5 VNC Client, works)
To use this Websockify server, follow the steps below:
- Clone the repository:
git clone https://github.com/morihofi/WebsockifyJava - Open it in your favorite IDE
publicstaticvoidmain(String[] args) {
//Websocket server settingsStringwsHost = "localhost";
intwsPort = 8090;
WebSocketServerserver = newWebsockifyServer(newInetSocketAddress(wsHost, wsPort), "192.168.178.1", 80);
server.run();
}This tunnels traffic from 192.168.178.1:80/TCP to a Websocket running on Port 8090 on your machine
publicstaticvoidmain(String[] args) throwsIOException {
StringwebsocketUrl = "ws://localhost:8090";
ServerSocketserverSocket = newServerSocket(7070);
while (true){
try {
Socketsocket = serverSocket.accept();
newThread(() -> {
//Handle connection in seperate Threadtry {
WebsockifyClientclient = newWebsockifyClient(newURI(websocketUrl), socket);
client.run();
} catch (URISyntaxExceptione) {
}
}).start();
} catch (IOExceptione) {
thrownewRuntimeException(e);
}
}
}This connects to ws://localhost:8090 and opens a TCP Socket on your machine on port 7070