title: Socket IO socket.on is not working after reconnection
body: <p>Whenever client turns on the remote management, The polling should start with the server ( Admin ). When the polling is started admin can send message to the client to turn on the VPN connection then send back the IP address generated by VPN back to the admin. This is what I'm trying to achieve right now I'm trying to send the static IP value but later I'll include the operations required for VPN. So basically I want to start the polling with admin when the client turns on the remote management and then admin sends message to turn on VPN, then receive the generated ip from client. I've created socket connection through node (server) and python (client) using socket.io, I am unable to print the message after receiving the message from the client after reconnection inside the post route. again when I restart the server It starts working but when the client disconnects and connects again that socket.on inside the post route is not working.</p>
  <p>This is the server code :</p>
  <pre><code>const express = require(&quot;express&quot;);
  const app = express();
  var server = require(&quot;http&quot;).createServer(app);
  
  var io = require(&quot;socket.io&quot;)(server, {
    cors: {
      origin: &quot;*&quot;,
      credentials: true,
      methods: [&quot;GET&quot;, &quot;POST&quot;],
    },
    serveClient: false,
  });
  
  app.set(&quot;socketio&quot;, io);
  app.use(express.json());
  const activeUsers = [];
  io.sockets.on(&quot;connection&quot;, (socket) =&gt; {
  
    socket.on(&quot;connected&quot;, (userid) =&gt; {
      //capturing the id
      socket.userId = userid;
      activeUsers[userid] = socket.id;
      console.log(activeUsers);
      socket.join(userid);
  
      //printing socket rooms!
      console.log(socket.rooms);
  
      //emitting the message to the client
      io.sockets.to(userid).emit(&quot;Hey&quot;, &quot;data&quot;);
  
      //receiving message from the client
      socket.on(&quot;python&quot;, (txt) =&gt; {
        console.log(txt);
      });
  
  
      //post api to send the vpn messsage and receive the ip
      app.post(&quot;/turnonvpn&quot;, async (req, res) =&gt; {
        let result = await req.body.status;
        let roomNum = await req.body.roomNum;
        console.log(result, roomNum);
        if (result === true) {
          io.sockets.in(roomNum).emit(&quot;vpnon&quot;, &quot;turnonvpn&quot;);
          **socket.on(&quot;generatedip&quot;, (txt) =&gt; {
            console.log(txt);
          });**
          res.send({ status: ipval });
        } else {
          socket.disconnect();
          res.send({ status: &quot;no&quot; });
        }
      });
    });
  
    socket.on(&quot;disconnect&quot;, () =&gt; {
      console.log(&quot;Disconnected&quot;);
    });
  
    socket.on(&quot;forceclose&quot;, (txt) =&gt; {
      socket.disconnect();
    });
  });
  
  server.listen(&quot;3001&quot;, () =&gt; {
    console.log(&quot;running&quot;);
  });
  </code></pre>
  <p>This is client code :</p>
  <pre><code>from requests import request
  import socketio
  from flask import Flask, jsonify, request
  
  app = Flask(__name__)
  
  sio = socketio.Client(reconnection=True, handle_sigint=True)
  
  
  @sio.event
  def connect():
      print('Polling Started with server')
      sio.emit(&quot;connected&quot;, 0)
  
  
  @sio.event
  def disconnect():
      print(&quot;Disconnected&quot;)
  
  
  @app.route('/pollingstatus', methods=['POST'])
  async def rmpolling():
      data = request.get_json()
      status = data['status']
      print(status)
      if status == &quot;True&quot;:
          try:
              sio.connect('http://localhost:3001', transports=['websocket'])
              sio.emit(&quot;python&quot;, &quot;I'm from pythin&quot;)
              return ({'status': True, 'result': &quot;Polling success&quot;})
          except:
              print(&quot;Error in Polling aka Socket IO&quot;)
              # sio.disconnect()
              sio.emit(&quot;forceclose&quot;, &quot;forceclose&quot;)
              return ({'status': False, 'result': 'error'})
      else:
          sio.emit(&quot;forceclose&quot;, &quot;forceclose&quot;)
          # sio.disconnect()
          return ({'status': False, &quot;result&quot;: &quot;userClosed&quot;})
  
  
  @sio.on(&quot;Hey&quot;)
  def on_message(txt):
      print(txt)
  
  
  @sio.on(&quot;vpnon&quot;)
  def on_message(txt):
      print(txt)
      if txt == 'turnonvpn':
          print(&quot;Generating VPN&quot;)
          sio.emit('generatedip', {&quot;ip&quot;: '123.156.3423'})
          print(&quot;Sent IP&quot;)
  
  
  if __name__ == '__main__':
      app.run()
  </code></pre>
  <p>Somebody help me to fix this issue, I've shared the code as well. socket.on is not working inside the post api when the client reconnects to the server until the server gets restart.
  The problem is with the node server not with the python which I'm aware of.</p>