Skip to content
Shadaï ALI edited this page Sep 15, 2017 · 1 revision

Welcome to the WebSocketAndroidClient wiki!

Usage

1 - Create an Web Socket Instance and start connection

  Ws ws = new Ws.Builder().from( "ws://server_address");
  ws.connect();

2 - Subscribe to channel

Basically get raw data

        ws.on("path/to/channel", new Ws.WsListner() {
            @Override
            public void onEvent(String eventUri, Object data) {
                if(data != null) //your logic here
            }
        });

OR

Get parsed object from json response, for example to get User from channel do something like this

        ws.on("path/to/channel", User.class, new Ws.WsListner<User>() {
            @Override
            public void onEvent(String eventUri, User user) {
                if(user != null) Log.e(TAG,user.name);
            }
        });

2 - Send data to server

ws.send("Hello World");

or send to specific channel

ws.send("path/to/channel","Hello Channel");