Answer the question
In order to leave comments, you need to log in
Telnet + Node.js (io.js). How to make control via telnet possible?
Speaking essentially, I wanted to have a local server on my computer so that I could manage it (my whim)))).
Why do you need to resort to telnet?
- Just a server, I can do it myself
- Everyone knows how to use a browser, but only a few know about telnet
- You need to be an Indian)
So, is it possible to do this at all?
Answer the question
In order to leave comments, you need to log in
For someone on the toaster already wrote this example:
'use strict';
const net = require('net');
const server = net.createServer(socket => {
var data = '';
socket.on('data', d => {
data += d;
var p = data.indexOf('\n');
if(~p) {
let cmd = data.substr(0, p);
data = data.slice(p + 1);
onCommand(cmd.trim(), socket);
}
});
});
server.listen(() => {
var address = server.address();
console.log('opened server on', address);
});
function onCommand(cmd, socket) {
switch(cmd) {
case 'open':
socket.write('opened\n');
break;
case 'add':
socket.write('added\n');
break;
case 'process':
socket.write('processed\n');
break;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question