!7 p { serveHttpWithWebsockets(8888, func(NanoHTTPD.IHTTPSession handshake) { ret new WebSocket(handshake) { protected void onPong(WebSocketFrame pongFrame) { print("pong"); } protected void onMessage(WebSocketFrame messageFrame) { print("msg: " + messageFrame.getTextPayload()); } protected void onClose(WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) { print("close"); } protected void onException(IOException e) { printStackTrace(e); } }; }); } html { ret "JavaScript doing its magic..." + hjavascript([[ var exampleSocket = new WebSocket("ws://localhost:8888/"); exampleSocket.onopen = function(event) { exampleSocket.send("Here is an important message!"); exampleSocket.close(); }; ]]); }