如何使用socket.io从节点连接到telnet服务器
我可能不会input正确的search条件,但我似乎无法find好的示例,允许我的节点应用程序启动一个socket.io客户端连接到另一个telnet服务器(非节点)。
下面是我的节点应用程序试图连接到远程login服务器
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
我已经从terminal成功telnet到telnet服务器。 错误的代码?
你不能。
Socket.IO与普通的TCPnetworking套接字无关。 Socket.IO是一个RPC层,通过几个传输(Web套接字,长轮询AJAX等)提供类似于networking套接字的function。 你不能只连接到你想要的任何服务器,你必须连接到一个Socket.IO服务器。 即使Web Sockets本身也有一个必须build立在HTTP之上的整个协议。
如果要连接到任意服务器以发送/接收数据,则必须通过Node.js应用程序将该连接代理到服务器端。 Socket.IO仅用于Socket.IO客户端和Socket.IO服务器之间的通信。
不知道如果这可以做,但看看这个包