0

in my app I'm trying to communicate with a node server. I have setup the sockets using socket-io client library and done my initialization like this:

public io.socket.client.Socket mSocket;
    try {
        mSocket = IO.socket(Constants.PUBLIC_CHAT_ENDPOINT);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

The client i.e my app connects successfully to server and my first emit test was successful like this:

mSocket.emit("send-message", "Hello Server");

But when I try to emit my message like this

    mSocket.on(Socket.EVENT_CONNECT, new io.socket.emitter.Emitter.Listener() {
        @Override
        public void call(Object... args) {
            Snackbar.make(findViewById(android.R.id.content), "Connected", BaseTransientBottomBar.LENGTH_SHORT).show();
            mSocket.emit(Constants.SOCKET_SEND_MESSAGE_EVENT, "Hello Server");
        }
    }). on("send-message", new io.socket.emitter.Emitter.Listener() {
        @Override
        public void call(Object... args) {
                JSONObject messageObject = new JSONObject();
                JSONObject metaMessageObject = new JSONObject();
                JSONObject moreDetails = new JSONObject();
                try {
                    moreDetails.put("roomId", chatRoomId);
                    moreDetails.put("userId", userId);
                    moreDetails.put("message", msg_body);

                    metaMessageObject.put("type", Constants.ChatCircle_Msg_Type);
                    metaMessageObject.put("content", moreDetails);

                    messageObject.put("data", metaMessageObject);

                    mSocket.emit("send-message", messageObject);

                } catch (JSONException e) {
                    e.printStackTrace();
                }
        }
    }).on(Constants.SOCKET_GET_MESSAGE_EVENT, new io.socket.emitter.Emitter.Listener() {
        @Override
        public void call(Object... args) {

        }
    });

    mSocket.connect();

, message is not registered. Pls am I doing this wrongly? Thanks everyone.

Anand Rajput
  • 469
  • 1
  • 8
  • 21
  • Did you check whether the client is even sending the messages? If it is, then there is a problem with the code on the client. – Jesse Schokker Nov 09 '17 at 12:24
  • @JesseSchokker, I have tried logging the message from client, not displaying. I have also tried emitting just a string inside my event function but still no response on server or client logs. – Anand Rajput Nov 09 '17 at 12:36

0 Answers0