I'm new to telnet and sockets and right now I'm all confused over its concepts. So I can use some help here.
So far I've created a simple telnet server using Node.js's package net. Here's a little snippet of that,
function newSocket(socket) {
sockets.push(socket);
console.log('A new telnet connection!\n');
socket.on('data', function(data) {
});
socket.on('end', function() {
console.log('A Telnet socket disconnected!\n');
});
}
var telnetServer = net.createServer(newSocket);
telnetServer.listen(8080);
It works perfectly on using command
telnet localhost 8080
and also I know I can connect to it using net package of NodeJS, like this
var client = net.connect({port: port}, function() {
console.log('client connected');
client.write('data!\r\n');
});
So, what I want to do is to connect to this telnet server from my client side application (AngularJS), if it's even possible.
I know how to connect to web sockets from AngularJS app using $websocket service, like this,
$websocket.$new({
url: websocketUrl,
protocols: [],
subprotocols: ['base46'],
reconnect: true,
reconnectInterval: 500
});
So, my questions are:
I know these questions sound silly, but like I said I have just started digging around about these things. Thanks for your time.
After going through various docs online, I got my answer. And as there is no answer yet (as of writing this), I am posting, what I found, one myself.
First of all, Answers of my Questions
Can I connect to telnet server from client-side? I mean is it even possible to connect to telnet from web browser like we do with web-sockets?
No, telnet is a protocol for the server, not some way to communicate between client and server. This was my biggest confusion which pushed me to ask this question here.
If yes, can you show me some kind of snippet for that?
Well, we can't, so no snippet.
Are web-sockets are better option than Telnet?
Both are different, so there is no comparison.
Solution
So what I did is, I used
So by this approach, I established a connection between telnet and websockets (which I needed in the first place), both are hosted on different server, and the server which was listening to web-socket, acted as telnet client.