Skip to content

A websocket implementation using NanoHTTPD and fast-json

License

Notifications You must be signed in to change notification settings

JohnLin8/fast-json-websocket

 
 

Repository files navigation

Credit:

This library uses both NanoHTTPD and nv-websocket-client to implement the JSON interface

How to get it:

Client:

Download

Server:

Download

How to use it:

Client:

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();

Server:

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();

About

A websocket implementation using NanoHTTPD and fast-json

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%