1

I am working on a game that is highly dependent on sockets. I want to create a socket connection to stay open even if the client has not logged in.

The game has one admin and few players. Admin has the right to override the player. So the below is the node js code in the backend of admin file (it just trigger socket in the player file) if admin choose to override the player:

  serverfile.app.io.route('forceForward', req => {
    req.io
      .room(req.session.user.game_id)
      .broadcast('gameforced');
    console.log('broadcast game force');
    }
  );

Here server file is the file which is running the app and it contains the library express.io with the var name app.

Below is the Javascript code which is triggered in the players front end screen:

  socket.on('gameforced', function() {
    socket.emit('buy', 0);
    window.location.replace('/buyer_wait')
  });

The code works fine and triggers the socket buy in the player file backend if the player is logged in but if the player is not logged in the socket doesn't work. Any suggestions.

Thanks

Karan
  • 115
  • 11
  • what kind of "sockets" ?! a socket cant held be open as long as you want. Your application design is bad. – Marc Jul 15 '20 at 20:50
  • I am calling the library `/socket.io/socket.io.js` in the front end javascript. And at the backend Node JS used the library `express.io`. When I check in the backend using `console.log`, it seems it is not receiving the message. – Karan Jul 15 '20 at 20:59
  • Please add more code, your backend & frontend: https://stackoverflow.com/help/minimal-reproducible-example – Marc Jul 15 '20 at 21:28
  • I have added the code, hope this helps. – Karan Jul 15 '20 at 22:05

0 Answers0