NodeJS-socket.io获取“访问被拒绝”例外 [英] NodeJS-socket.io getting "Access is Denied" Exception

查看:569
本文介绍了NodeJS-socket.io获取“访问被拒绝”例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在FF中运行良好的节点(0.6.11)/socket.io(0.9.0)应用程序,但IE8引发JS异常:

I have a node (0.6.11)/socket.io(0.9.0) application that runs well in FF but IE8 throws JS exceptions:

Access is denied

req.open(method || 'GET', this.prepareUrl() + query, true);

之前的几行,req定义为

a few lines before that, req is defined as

req = io.util.request(this.socket.isXDomain())

这表明这是一个跨域问题,但我在本地一路做。 Plus FF没有问题。

This suggests it is a cross domain issue, but I'm doing it locally all the way. Plus FF has no issues.

可能是什么原因?

以下是源代码:

服务器:

var app = require('express').createServer()
  , io = require('socket.io').listen(app);

app.listen(1337);

app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});

io.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});

客户:

<html>
    <head>
    </head>
    <body>        
        <div id='contents'> 
        </div>
        <script src="http://localhost:1337/socket.io/socket.io.js"></script>
        <script>
          var socket = io.connect('http://127.0.0.1:1337');
          socket.on('news', function (data) {
            console.log(data);
            socket.emit('my other event', { my: 'data' });
          });
        </script>
    </body>
</html>



我读了关于将安全标志设置为true,使异常消失,并且什么也不做。在FF和IE。

I read about setting the secure flag to true and that makes the exception go away but then it siliently fails and does nothing. In FF and IE.

推荐答案

抱歉没有人打扰你回答,但问题是你正在做CORS,原始资源共享),意味着你的socket.io服务器运行在不同的端口上,从你的web服务器(我假设端口80,但你没有明确说它)

sorry nobody bothers to answer you, but the issue is that you are doing CORS, (cross-origin-resource-sharing), meaning your socket.io server is running on a different port from your webserver (i assume port 80, but you don't explicitly say it)

IE8和IE9有非常有限的CORS支持。我不知道IE8支持的解决方案,但这是你的问题。更多详情可以在这里找到: http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

the IE8 and IE9 have very limited CORS support. i don't know a solution for IE8 support, but that's your problem. more details can be found here: http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

这篇关于NodeJS-socket.io获取“访问被拒绝”例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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