如何使用 socket.io 从节点连接到 telnet 服务器 [英] How to connect to a telnet server from node using socket.io

查看:18
本文介绍了如何使用 socket.io 从节点连接到 telnet 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能没有输入正确的搜索词,但我似乎找不到允许我的节点应用程序启动 socket.io 客户端连接到另一个 telnet 服务器(非节点)的好例子.

I may not be entering the correct search terms but I cannot seem to find good examples that allow my node application to initiate a socket.io client connection to another telnet server (non-node).

下面是我的节点应用程序尝试连接到 telnet 服务器

Below is my node app trying to connect to a telnet server

var ioc = require('socket.io-client'),
clientSocket = ioc.connect('192.168.1.97', {
    port: 23
});
clientSocket.on('connect', function(){
  console.log('connected to to telnet');
});
clientSocket.on('connect_error', function(data){
  console.log('connection error to telnet');
  console.log(data);
});
clientSocket.on('connect_timeout', function(data){
  console.log('connection timeout to telnet');
  console.log(data);
});

这是我得到的错误

connection error to telnet
timeout
connection timeout to telnet
20000

我已经成功地从终端直接 telnet 到 telnet 服务器.错误代码?

I've telneted directly to the telnet server successfully from the terminal. Bad code?

推荐答案

你不能.

Socket.IO 与常规 TCP 网络套接字无关.Socket.IO 是一个 RPC 层,通过多种传输(Web 套接字、长轮询 AJAX 等)提供类似 Web 套接字的功能.你不能只是连接到任何你想要的服务器,你必须连接到 Socket.IO 服务器.甚至 Web Sockets 本身也有一个建立在 HTTP 之上的完整协议,必须进行设置.

Socket.IO has nothing to do with regular TCP network sockets. Socket.IO is an RPC layer providing web-socket-like functionality over several transports (Web Sockets, long-polling AJAX, etc.). You can't just connect to any server you want, you must connect to a Socket.IO server. Even Web Sockets itself has a whole protocol built on top of HTTP that must be set up.

如果您想连接到任意服务器以发送/接收数据,则必须通过您的 Node.js 应用程序在服务器端代理该连接.Socket.IO 仅用于 Socket.IO 客户端和 Socket.IO 服务器之间的通信.

If you want to connect to an arbitrary server to send/receive data, that connection must be proxied server-side through your Node.js application. Socket.IO is only for communication between a Socket.IO client and a Socket.IO server.

这篇关于如何使用 socket.io 从节点连接到 telnet 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆