title: Socket.IO-client Java with Header
body: <p>I have socket server that need user-id in order to connect. Therefore, I need to set extraHeader to connection constructor. I tried the following code but there's no luck. Please help me get through, thanks.</p>
  
  <p>Add extra header 'x-user-id': userId to connection constructor</p>
  
  <pre><code>private Socket mSocket;
  {
      try {
          IO.Options opts = new IO.Options();
          mSocket = IO.socket(socket_url, opts);
          mSocket.io().on(Manager.EVENT_TRANSPORT, new Emitter.Listener() {
              @Override
              public void call(Object... args) {
  
                  Transport transport = (Transport)args[0];
                  transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() {
                      @Override
                      public void call(Object... args) {
                          @SuppressWarnings("unchecked")
                          Map&lt;String, List&lt;String&gt;&gt; headers = (Map&lt;String, List&lt;String&gt;&gt;)args[0];
                          // modify request headers
                          headers.put("x-user-id", Arrays.asList("5B59F68B7B7811E88C3E52964BF487E4"));
                      }
                  }).on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() {
                      @Override
                      public void call(Object... args) {
                      }
                  });
              }
          });
  
      } catch (URISyntaxException e) {}
  }
  </code></pre>
  
  <p>This is my swift code that is works.</p>
  
  <pre><code>private init(){
          self.socketManager = SocketManager(socketURL: URL(string:"\(MAIN_URL)/message")!, config: [.log(true),.extraHeaders(["x-user-id":AppManager.instance.userId])])
          self.socket = socketManager?.defaultSocket
      }
  </code></pre>