Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't seem to disconnect? #46

Open
eX-C0n opened this issue Oct 6, 2022 · 1 comment
Open

Doesn't seem to disconnect? #46

eX-C0n opened this issue Oct 6, 2022 · 1 comment

Comments

@eX-C0n
Copy link

eX-C0n commented Oct 6, 2022

When I run this code via a discord command, it will successfully send the command to the server, and successfully send the response of the command!
The .on('end',()) function fires off after exactly 1 hour.
So, attempting to run another command, within that hour, consistently results in:
"Error: connect ETIMEDOUT :".
The only way I've found to get around this limitation is to reboot my discord bot via process.exit(). Once rebooted, it will work one time again.

Having that been said, I am currently forcing my bot to reboot every time this particular discord command is ran, so that I can use commands without having to manually reboot.
(I've commented the process.exit() in the code below, as the below code is what is currently a 1-time-use command.

Is there a way to get around this? To limit the time the socket connection stays open? conn.disconnect(); does not disconnect the socket connection.

let Rcon = require('rcon')
    const conn = new Rcon(process.env.IP, process.env.PORT, process.env.PASSWORD);
    try {
      message.channel.send(`Please wait for Server Authentication:`)
      conn.connect();
      conn.on('auth', function () {
        // You must wait until this event is fired before sending any commands,
        // otherwise those commands will fail.
        message.channel.send(`Authenticated - Sending command: ${args.join(" ")}`);
        conn.send(args.join(" "));
      }).on('response', (str) => {
        message.channel.send("Response: " + str);
        //process.exit()
      }).on('end', () => {
        message.channel.send("Rcon socket closed!");
      }).on('error', (error) => {
        message.channel.send(`Error ${error}`)
        conn.disconnect();
      });
    } catch (error) {
      console.error(error)
    }
@pushrax
Copy link
Owner

pushrax commented Oct 10, 2022

It looks like the server-side socket is timing out since there's not much traffic on the connection. Two things you could try:

  • Disconnect the connection on response, and reconnect when you want to send another command. This makes sense if you're only sending commands once in a while.
  • Send a ping once in a while (e.g. every 10 seconds) to keep the connection alive. This makes sense if you're sending commands fairly frequently and want to ensure the lowest latency possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants