Skip to content

Doesn't seem to disconnect? #46

Description

@eX-C0n

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)
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions