Closed SvenC56 closed 5 years ago
I came along this Issue #78 . I adapted this soultion for my question.
'use strict'
require('dotenv').config();
const Telnet = require('telnet-client');
const host = process.env.HOST;
const port = process.env.PORT;
async function run() {
const connection = new Telnet();
connection.on('connect', () => {
console.log('connection established');
});
connection.on('timeout', () => {
console.log('socket timeout!');
connection.end();
});
connection.on('close', () => {
console.log('connection closed');
});
connection.on('ready', (prompt) => {
console.log('connected');
});
const params = {
host,
port,
shellPrompt: 'Welcome to the TeamSpeak 3 ServerQuery interface, type "help" for a list of commands and "help <command>" for information on a specific command.',
negotiationMandatory: false,
debug: true,
timeout: 2000,
irs: '\n\r',
echoLines: -1
};
try {
await connection.connect(params);
} catch(error) {
// handle the throw (timeout)
console.error(error);
}
try {
let data = await connection.exec('version', { shellPrompt: 'error id=0 msg=ok'})
console.log(data.toString());
} catch(error) {
console.error(error);
}
try {
let data = await connection.exec('version', { shellPrompt: 'error id=0 msg=ok'})
console.log(data.toString());
} catch(error) {
console.error(error);
}
// End Connection when everything is done.
await connection.end();
}
run();
Console Outputs looks now the following:
connection established
TS3
Welcome to the TeamSpeak 3 ServerQuery interface, type "help" for a list of commands and "help <command>" for information on a specific command.
version=3.7.1 build=1553759186 platform=Linux
error id=0 msg=ok
version=3.7.1 build=1553759186 platform=Linux
error id=0 msg=ok
connection closed
How do I cut off the empty lines and the first line "Welcome to TeamSpeak..."?
Thank you.
Hi, @SvenC56! The only thing you can try is setting echoLines
to a positive value when running exec()
. I see you've set it initially to -1
which is not really a valid line.
Please reopen if needed!
Hi,
I'm working on a TeamSpeak3 Server Rest API based on Express. For this purpose I want to include this library.
Typically when I connect to TeamSpeak Telnet Service it looks the following:
Unknown Command error:
correct command response:
Tbh I'm fairly new to telnet. So I made a lot of trial and error. I prepared the telnet service the following way:
Now I like to execute the "version" command which is public. When I do connection.exec('version'). I do net get any response. Login is done via the login method (see https://sk-gameservers.de/ts3-server-query-befehle-alle#login).
The console output looks the following:
I hope anyone can help.
Thank you.