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

Telnet connection breaks a process #211

Open
barwalker opened this issue May 31, 2022 · 1 comment
Open

Telnet connection breaks a process #211

barwalker opened this issue May 31, 2022 · 1 comment
Labels

Comments

@barwalker
Copy link

Hi, I try to send a connecting request to an IP and it refuses with this message:
in terminal:

$ telnet 10.123.9.236 2361
Trying 10.123.9.236...
Connected to 10.123.9.236.
Escape character is '^]'.
*** Maximum number of clients reached.
  * Please, try again later.
  * Exiting...
Connection closed by foreign host.

That issue interrupts the code below:

let connection = new Telnet();
 let params = {
     host: '10.123.9.236',
     port: 2361,
     negotiationMandatory: false,
     shellPrompt: '/ # ',
     ors: '\r\n', // mandatory for your 'send' to work
     timeout: 1000,
     sendTimeout: 2000,
     maxBufferLength: '5M'
 };

 try {
     await connection.connect(params);
     console.log(ip, 222);
     let xxx = await connection.send('act-user::abcdef::Wsn7;', {waitfor: ';\r\n>'});
     console.log(ip, 333, xxx);
 } catch (error) {
     console.log(ip, 'error::', error.toString());
 }

Output:

$ node test.js
10.123.9.236 222
$

It breaks the whole process, it should raise an error and runs into a catch block.
Please help me handle this problem.

@zxdong262
Copy link

zxdong262 commented Sep 29, 2023

I encounter this situation myself, there could be some error happens that try catch block can not catch, one way to handle it is use this:

process.on('uncaughtException', (err) => {
  console.error('uncaughtException', err)
})
process.on('unhandledRejection', (err) => {
  console.error('unhandledRejection', err)
})

Not elegant, just saved process from broken

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

No branches or pull requests

3 participants