1
 JSONObject getobj = new JSONObject();

        postobj.put("url", String.format("/user"));

        Log.d("Get MEthod", getobj.toString() + ">>>>>>>>>>>>>>>>>>>>Get Message " + socket.connected());

        Log.d(TAG, " the meessage url " + getobj.toString());

        socket.emit("get",getobj, new Ack() {
            @Override
            public void call(Object... args) {

                JSONObject obj = (JSONObject) args[0];

                Log.d("GET CHAT MEESSAGE ", obj.toString() + ">>>>>>>>>>>>>>>>>>>> with in call method Get Message " + socket.connected());

            }
        });

/I got Bellow response\

   {
   "body": {
      "err": "No Authorization header was found"
     },
   "headers": {

   },
   "statusCode": 401
  }
Dileep Patel
  • 1,988
  • 2
  • 12
  • 26
user3334050
  • 21
  • 1
  • 2

2 Answers2

2

This is how i add authorization token for Socket connection, Hope this helps

IO.Options options = new IO.Options(); 
options.forceNew = true;                        
options.reconnectionAttempts = Integer.MAX_VALUE;                    
options.timeout = 10000;    
options.query = "token=" + "your_authorization_code";
RamaKrishnan
  • 179
  • 9
1

For passing header is IO.socket we need to create Options for that

        val options = Options
            .builder()
            .setExtraHeaders(
                mapOf("Authorisation" to listOf("TOKEN"))
            )

and then pass it to IO.socket

IO.socket("URL", options)