简体   繁体   English

独立的socket.io和Websocket

[英]Standalone socket.io and Websocket

I need to build a socket.io server that will intercept incoming connections from an app which is not stored in the same directory as the server. 我需要构建一个socket.io服务器,该服务器将拦截来自未与该服务器存储在同一目录中的应用程序的传入连接。

The client side app does not contain node.js, thus I'm trying to use a websocket : 客户端应用程序不包含node.js,因此我尝试使用websocket:

Telnet.Socket = new WebSocket('ws://127.0.0.1:3000');

My node.js server does not need a http server but must be a standalone socket.io app. 我的node.js服务器不需要http服务器,但必须是独立的socket.io应用程序。 Thus, I've tried the following code : 因此,我尝试了以下代码:

var io = require('socket.io')();
io.on('connection', function(socket){
    console.log('connexion entrante');
});
io.listen(3000);

Unfortunately, the server part does not seem to get the Websocket connection request. 不幸的是,服务器部分似乎没有收到Websocket连接请求。 My firefox says : 我的Firefox说:

Firefox cannot establish a connection with the server at adress ws://127.0.0.1:3000/. Firefox无法通过地址ws://127.0.0.1:3000 /与服务器建立连接。

What am I missing ? 我想念什么?

Thx in advance ! 提前谢谢!

socket.io need client use socket.io to connect because it use many kind of connection. socket.io需要客户端使用socket.io进行连接,因为它使用多种连接方式。 For connect websocket only you can use ws node module 仅用于连接websocket,可以使用ws节点模块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM