Exemplo n.º 1
0
  public Dealoka() {
    try {
      socket = new SocketIO("http://54.169.132.22:3001");
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }

    if (socket != null) {
      socket.connect(
          new IOCallback() {
            @Override
            public void onMessage(JSONObject json, IOAcknowledge ack) {
              try {
                Log.d("socket-io", "Server said:" + json.toString(2));
              } catch (JSONException e) {
                e.printStackTrace();
              }
            }

            @Override
            public void onMessage(String data, IOAcknowledge ack) {
              Log.d("socket-io", "Server said: " + data);
            }

            @Override
            public void onError(SocketIOException socketIOException) {
              Log.d("socket-io", "an Error occured");
              socketIOException.printStackTrace();
            }

            @Override
            public void onDisconnect() {
              Log.d("socket-io", "Connection terminated.");
            }

            @Override
            public void onConnect() {
              Log.d("socket-io", "Connection established");
            }

            @Override
            public void on(String event, IOAcknowledge ack, Object... args) {
              Log.d("socket-io", "Server triggered event '" + event + "'");
            }
          });
    } else {
      Log.e(TAG, "socket is null");
    }
  }
 public void sentEmit(String message) throws Exception {
   socket = new SocketIO();
   socket.connect("http://192.168.1.4:3000", this);
   socket.emit("my other event", message);
 }