简体   繁体   English

尝试使用Socket.IO名称空间会导致404轮询错误

[英]Trying to use Socket.IO namespaces causes 404 polling error

When I use Socket.IO to connect like normal/default 当我使用Socket.IO进行正常/默认连接时

var client = io.connect('http://localhost:466/');

It works/connects just fine. 它可以正常工作/连接。 No errors in console. 控制台中没有错误。

However, when I want to try connecting to a namespace like so 但是,当我想尝试连接到这样的名称空间时

var client = io('/adm').connect('http://localhost:466/');

I get the following errors 我收到以下错误

在此处输入图片说明

The admin namepsace is created on the server 管理员名称psace在服务器上创建

//start server
var server = require('socket.io').listen(466);

//admin namespace
var adm = server.of('/adm');

adm.on('connection', function(client){
    console.log('adm connection');
});

The issue was that I was trying 问题是我在尝试

var client = io('/adm').connect('http://localhost:466/');

instead of 代替

var client = io.connect('http://localhost:466/adm');

Which I find odd, because the documentation seemed to recommend the first method. 我觉得很奇怪,因为文档似乎推荐了第一种方法。

http://socket.io/docs/rooms-and-namespaces/#custom-namespaces http://socket.io/docs/rooms-and-namespaces/#custom-namespaces

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

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