Giter VIP home page Giter VIP logo

clusterws-client-java's Issues

version of library

hi
i added this line to my build.gradle file:
implementation 'com.github.ClusterWS:ClusterWS-Client-Java:1.1.1'
Has the correct version been added?

socket.send

Submitting

  • Bug
  • Question
  • Suggetion
  • Other

Details

hi
I use the following code to watch from channel:

ClusterWS socket ;
oncreate (){
     initChat();
}
  private void initChat() {
    socket = new ClusterWS("url");
    socket.connect();
    socket.setReconnection(true, 2, 10, 20);

    socket.setClusterWSListener(new IClusterWSListener() {
      @Override
      public void onConnected() {
        Channel channel = socket.subscribe("match-wall");
        channel.watch(new Channel.IChannelListener() {
          @Override
          public void onDataReceived(String channelName, Object data) {
            Gson gson = new Gson();
            String json = gson.toJson(data);
            try {
              JSONObject object = new JSONObject(json);
              String action = object.getString("action");
              if (action.equals("publish")) {
                String username = object.getString("username");
                String message = object.getString("message");
                String photo = object.getString("photo");
                addMessage(username, message, photo);
              } else if (action.equals("number-of-users")) {
                //Todo
              }
            } catch (JSONException e) {
              e.printStackTrace();
            }

          }
        });
      }

      @Override
      public void onError(Exception exception) {
      }

      @Override
      public void onDisconnected(int code, String reason) {
      }
    });
  }

and this code to send data to server:

private void sendMessage() {
    hideKeyboard();
    String message = edtChatMsg.getText().toString().trim();
    if (TextUtils.isEmpty(message)) {
      edtChatMsg.requestFocus();
      return;
    }
    edtChatMsg.setText("");

    final JSONObject jsonObject = new JSONObject();
    try {
      jsonObject.put("username", mUsername);
      jsonObject.put("message", message);
    } catch (JSONException e) {
      e.printStackTrace();
    }

    Channel channel = socket.getChannelByName("match-wall");
    if (channel != null) {
      socket.send("match-wall-send-message", jsonObject.toString());
    } 
  }

but socket.send not working.....
I am sincerely thankful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.