title: Why the connection function is not activated when Python socketio client connects to Go socketio server?
body: <p>I built a socket.io client by using <a href="https://python-socketio.readthedocs.io/en/latest/client.html" rel="nofollow noreferrer">Python Socket.IO</a>:</p>
  <pre><code>import socketio
  import time
  
  sio = socketio.Client(logger=True, engineio_logger=True)
  is_connect = False
  
  @sio.on(&quot;connect&quot;)
  def connect():
      global is_connect
      print(&quot;is_connect value before connect:&quot;, is_connect)
      is_connect = True
      print(f&quot;connection established with sid {sio.sid}&quot;)
      
  def message_received(data):
      print(f'message was received!!!\n')
      print(f&quot;message returned from server: {data}&quot;)
  
  @sio.on(&quot;message&quot;)
  def my_message(data):
      print(&quot;Messages from server: &quot;, data)
  
  @sio.on(&quot;disconnect&quot;)
  def disconnect():
      global is_connect
      print(&quot;is_connect value before disconnet:&quot;, is_connect)
      is_connect = False
      print(&quot;disconnected from server&quot;)
  
  sio.connect(&quot;http://localhost:9000&quot;) 
  time.sleep(3)
  sio.emit(&quot;chat message&quot;, &quot;Hello!&quot;, callback=message_received)
  time.sleep(3)
  sio.disconnect()
  </code></pre>
  <p>And then I built a socket.io server in Go by using <a href="https://github.com/pschlump/socketio" rel="nofollow noreferrer">an online example</a>:</p>
  <pre><code>package main
  
  //
  // Command line arguments can be used to set the IP address that is listened to and the port.
  //
  // $ ./chat --port=8080 --host=127.0.0.1
  //
  // Bring up a pair of browsers and chat between them.
  //
  
  import (
      &quot;flag&quot;
      &quot;fmt&quot;
      &quot;log&quot;
      &quot;net/http&quot;
      &quot;os&quot;
  
      &quot;github.com/mlsquires/socketio&quot;
      &quot;github.com/pschlump/MiscLib&quot;
      &quot;github.com/pschlump/godebug&quot;
  )
  
  // Port is the port to listen to
  var Port = flag.String(&quot;port&quot;, &quot;9000&quot;, &quot;Port to listen to&quot;) 
  // HostIP is the host name or IP address to listen on
  var HostIP = flag.String(&quot;host&quot;, &quot;localhost&quot;, &quot;Host name or IP address to listen on&quot;) 
  // Dir is the directry where files are served from
  var Dir = flag.String(&quot;dir&quot;, &quot;./asset&quot;, &quot;Direcotry where files are served from&quot;) 
  func init() {
      flag.StringVar(Port, &quot;P&quot;, &quot;9000&quot;, &quot;Port to listen to&quot;)                           
      flag.StringVar(HostIP, &quot;H&quot;, &quot;localhost&quot;, &quot;Host name or IP address to listen on&quot;) 
      flag.StringVar(Dir, &quot;d&quot;, &quot;./asset&quot;, &quot;Direcotry where files are served from&quot;)     
  }
  
  func main() {
  
      flag.Parse()
      fns := flag.Args()
  
      if len(fns) != 0 {
          fmt.Printf(&quot;Usage: Invalid arguments supplied, %s\n&quot;, fns)
          os.Exit(1)
      }
  
      var hostIP string = &quot;&quot;
      if *HostIP != &quot;localhost&quot; {
          hostIP = *HostIP
      }
  
      // Make certain that the command line parameters are handled correctly
      // fmt.Printf(&quot;host_ip &gt;%s&lt; HostIP &gt;%s&lt; Port &gt;%s&lt;\n&quot;, host_ip, *HostIP, *Port)
  
      server, err := socketio.NewServer(nil)
      if err != nil {
          log.Fatal(err)
      }
  
      server.On(&quot;connection&quot;, func(so socketio.Socket) {
          fmt.Printf(&quot;%sa user connected with id %s%s, %s\n&quot;, MiscLib.ColorGreen, so.Id(), MiscLib.ColorReset, godebug.LF())
          so.Join(&quot;chat&quot;)
          so.On(&quot;chat message&quot;, func(msg string) string {
              fmt.Printf(&quot;%schat message, %s%s, %s\n&quot;, MiscLib.ColorGreen, msg, MiscLib.ColorReset, godebug.LF())
              so.BroadcastTo(&quot;chat&quot;, &quot;message&quot;, msg)
              return msg
          })
          so.On(&quot;disconnect&quot;, func() {
              fmt.Printf(&quot;%suser disconnect%s, %s\n&quot;, MiscLib.ColorYellow, MiscLib.ColorReset, godebug.LF())
          })
      })
  
      server.On(&quot;error&quot;, func(so socketio.Socket, err error) {
          fmt.Printf(&quot;Error: %s, %s\n&quot;, err, godebug.LF())
      })
  
      http.Handle(&quot;/socket.io/&quot;, server)
      http.Handle(&quot;/&quot;, http.FileServer(http.Dir(*Dir)))
      fmt.Printf(&quot;Serving on port %s, brows to http://localhost:%s/\n&quot;, *Port, *Port)
      listen := fmt.Sprintf(&quot;%s:%s&quot;, hostIP, *Port)
      log.Fatal(http.ListenAndServe(listen, nil))
  }
  </code></pre>
  <p>When the client tries to connect to the server, the connection does happen. However, the connect function in Python socket.io client is not activated. Here are the logs when the connection is established:</p>
  <pre><code>Attempting polling connection to http://localhost:9000/socket.io/?transport=polling&amp;EIO=3
  Polling connection accepted with {'sid': 'Kon2_JkRCg9o4B8F_8Ab', 'upgrades': ['websocket'], 'pingInterval': 25000, 'pingTimeout': 60000}
  Engine.IO connection established
  Attempting WebSocket upgrade to ws://localhost:9000/socket.io/?transport=websocket&amp;EIO=3
  WebSocket upgrade was successful
  Sending packet PING data None
  Received packet PONG data None
  Received packet PING data None
  Received unexpected packet of type 2
  Sending packet PING data None
  Received packet PONG data None
  </code></pre>
  <p>Meanwhile, the &quot;chat message&quot; and &quot;disconnect&quot; events work well and their functions are all activated, and the callback function also works.</p>
  <p>Why is the connect function in Python socket.io client not activated when the socket.io connection is established? Did I miss anything? Please give me some feedback, thank you!</p>