title: I need solve a problem with websockets on golang server
body: <p>I have a server on GoLang and <code>googollee/go-socket.io</code>.
  <br>When the server and the client work on the same port, the sockets work normally. But when I start they are on different ports an error occurs on the client:</p>
  <blockquote>
  <p><code>WebSocket connection to 'ws://localhost:4444/socket.io/?EIO=3&amp;transport=websocket&amp;sid=6' failed: Error during WebSocket handshake: Unexpected response code: 403</code></p>
  </blockquote>
  <blockquote>
  <p><code>POST http://localhost:4444/socket.io/?EIO=3&amp;transport=polling&amp;t=NDDzcYM&amp;sid=5 400 (Bad Request)</code></p>
  </blockquote>
  <blockquote>
  <p><code>GET http://localhost:4444/socket.io/?EIO=3&amp;transport=polling&amp;t=NDDzcYC&amp;sid=5 400 (Bad Request)</code></p>
  </blockquote>
  <blockquote>
  <p><code>WebSocket connection to 'ws://localhost:4444/socket.io/?EIO=3&amp;transport=websocket&amp;sid=5' failed: Error during WebSocket handshake: Unexpected response code: 403</code></p>
  </blockquote>
  <p>And on the server:</p>
  <blockquote>
  <p><code>connected: 1 closed client namespace disconnect meet error: json: cannot unmarshal object into Go value of type string connected: 2</code></p>
  </blockquote>
  <p>This is my code:</p>
  <pre><code>package main
  
  import (
  &quot;fmt&quot;
  &quot;log&quot;
  &quot;net/http&quot;
  &quot;github.com/gorilla/mux&quot;
  &quot;github.com/rs/cors&quot;
  
  socketio &quot;github.com/googollee/go-socket.io&quot;
  )
  
  func main() {
  fmt.Println(&quot;Hello world&quot;)
  router := mux.NewRouter()
  router.HandleFunc(&quot;/is-alive&quot;, isAlive).Methods(&quot;GET&quot;)
  
  server, err := socketio.NewServer(nil)
  if err != nil {
      log.Fatal(err)
  }
  
  server.OnConnect(&quot;/&quot;, func(s socketio.Conn) error {
      s.SetContext(&quot;&quot;)
      fmt.Println(&quot;connected:&quot;, s.ID())
      s.Emit(&quot;change&quot;)
      s.Join(&quot;bcast&quot;)
      return nil
  })
  
  server.OnEvent(&quot;/&quot;, &quot;msg&quot;, func(s socketio.Conn, msg string) string {
      s.SetContext(msg)
      s.Emit(&quot;change&quot;)
      fmt.Println(&quot;event: msg&quot;)
      return &quot;recv &quot; + msg
  })
  
  server.OnError(&quot;/&quot;, func(s socketio.Conn, e error) {
      fmt.Println(&quot;meet error:&quot;, e)
  })
  
  server.OnDisconnect(&quot;/&quot;, func(s socketio.Conn, reason string) {
      fmt.Println(&quot;closed&quot;, reason)
  })
  
  go server.Serve()
  defer server.Close()
  
  router.Handle(&quot;/socket.io/&quot;, server)
  c := cors.New(cors.Options{
      AllowedOrigins: []string{&quot;http://localhost:3000&quot;},
      AllowCredentials: true,
  })
  handler := c.Handler(router)
  
  log.Println(&quot;Serving at localhost:4444...&quot;)
  log.Fatal(http.ListenAndServe(&quot;:4444&quot;, handler))
  }
  
  func isAlive(w http.ResponseWriter, r *http.Request) {
  w.WriteHeader(http.StatusOK)
  }
  </code></pre>
  <p>On my react app</p>
  <pre><code> import socketIOClient from &quot;socket.io-client&quot;;
  
   export class SocketClientManager {
  
   public socket = socketIOClient(&quot;ws://localhost:4444&quot;);
  
   public subscribe() {
      this.socket.emit(&quot;msg&quot;, { msg: &quot;Hello!&quot; });
   }
  
   public setCallback(callback: (arg: any) =&gt; void) {
      this.socket.on(&quot;change&quot;, callback);
   }
  
   public async unsubscribe() {
      this.socket.disconnect();
   }
  </code></pre>
  <p>}</p>