This library uses both NanoHTTPD and nv-websocket-client to implement the JSON interface
JSONWebSocketClient client = new JSONWebSocketClient();
client.connect("ws://localhost:80");
client.setHandler(new JSONWebSocketHandler() {
public void onConnect(JSONWebSocketClient socket) { }
public void onDisconnect(JSONWebSocketClient socket) { }
public void onMessage(JSONWebSocketClient socket, JSONObject object) { }
public void onPong(JSONWebSocketClient socket, ByteBuffer data) { }
public void onError(JSONWebSocketClient socket, Throwable t) { }
});
JSONObject example = new JSONObject();
example.put("key", "value");
client.send(example);
client.disconnect();
JSONWebSocketServer server = new JSONWebSocketServer(80);
server.setHandler(new JSONWebSocketConnectionHandler() {
public void onConnect(JSONWebSocketConnection socket) { }
public void onDisconnect(JSONWebSocketConnection socket) { }
public void onMessage(JSONWebSocketConnection socket, JSONObject object) { }
public void onPong(JSONWebSocketConnection socket, ByteBuffer data) { }
public void onError(JSONWebSocketConnection socket, Throwable t) { }
});
server.start();
// ...
server.stop();