Socket.io v1.0.X未知传输"轮询"

use*_*055 2 websocket node.js socket.io

Y在连接版本1.0中有一个问题,我在0.9.X版本中没有这个问题.

我在http://app.myhost.com运行Django,在http://live.myhost.com:8001运行我的节点服务器

之前我可以将我连接到节点服务器,如:

客户:

io.connect(//live.myhost.com:8001);
Run Code Online (Sandbox Code Playgroud)

服务器:

io.set('transports', ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']);
Run Code Online (Sandbox Code Playgroud)

但现在我遇到了问题(没有正确使用实时网址):

GET http://app.myhost.com:8000/socket.io/?EIO=2&transport=polling&t=1401468282894-1 404 (NOT FOUND)
Run Code Online (Sandbox Code Playgroud)

如果我重写(io.connect(http://live.myhost.com:8001))现在有一个新问题:

XMLHttpRequest cannot load http://live.myhost.com:8001/socket.io/?EIO=2&transport=polling&t=1401468608168-1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://app.myhost.com' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)

在调试模式下socket.io我有更多的信息:

engine:core intercepting request for path "/socket.io/" +0ms
engine handling "GET" http request "/socket.io/?EIO=2&transport=polling&t=1401470024479-48" +0ms
engine unknown transport "polling" +3ms
Run Code Online (Sandbox Code Playgroud)

tea*_*wyx 11

在默认Socket.IO 1.0.4允许pollingwebsocket传输中.您polling通过设置自定义传输删除了传输.只需返回polling运输:

io.set('transports', ['websocket', 
                      'flashsocket', 
                      'htmlfile', 
                      'xhr-polling', 
                      'jsonp-polling', 
                      'polling']);
Run Code Online (Sandbox Code Playgroud)

2015年4月3日更新

0.9.15是有效set方法的最后一个版本.版本1.0.0-pre删除set方法并通过服务器初始化引入设置.版本1.0.0-pre2添加set了向后兼容的原始方法.使用新的表示法:

var socket = io({
  transports: [
    'websocket', 
    'flashsocket', 
    'htmlfile', 
    'xhr-polling', 
    'jsonp-polling', 
    'polling'
  ]
});
Run Code Online (Sandbox Code Playgroud)

  • 从Socket1 .set开始不推荐使用,所以你应该修改你的答案. (3认同)