Socket.io在IE8上不起作用

时间:2014-12-30 14:13:19

标签: node.js socket.io

您好我已经使用nodejs和socket.io开发了一个小应用程序,以便我可以利用socket.io的推送机制。

它在Firefox,Chrome和Safari上的功能就像魅力一样,但无法在IE8上运行。

我收到此错误
[WebSocket] cannot connect to Web Socket server at ws://socketio-example.nodester.com:80/socket.io/1/flashsocket/1574670559846521853 (SecurityError) make sure the server is running and Flash socket policy file is correctly placed

经过大量的谷歌搜索,我得到了在socket.io上设置传输的信息,我只限于

io.set('transports', [
'jsonp-polling'
]);

在此之后我没有看到错误但内容正在加载。

如果我想真正设置Falsh政策文件的确切内容和我应该放在哪里。

长期以来苦苦挣扎,现在需要一些建议。

这是我的服务器端代码供参考

var app = require('express')
    //var  httpapp = require('http')
, fs = require('fs')
 //http = require('http').createServer(httpapp)
, server = require('http').createServer(handler)
, io = require('socket.io').listen(server)
, firstTime;

//httpapp.get('*',function(req,res){ 
//    res.redirect('https://itcomm-dev.vmware.com:8080'+req.url)
//})
io.set('flash policy port', 10483)
io.set('transports', [
   //  'websocket'
   //, 'flashsocket'
//   , 'htmlfile'
//   , 'xhr-polling'
    'jsonp-polling'
 ]);
//io.set('flash policy port', -1)
io.set("polling duration", 60)
server.listen(8083);

// on server started we can load our client.html page
function handler(req, res) {
  fs.readFile(__dirname + '/../index.html', function(err, data) {
    if (err) {
      //console.log(err);
      res.writeHead(500);
      return res.end('Error loading client.html');
    }
    res.writeHead(200, {'Access-Control-Allow-Origin': '*','Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE',
                        'Access-Control-Allow-Headers': 'X-Requested-With, Accept, Origin, Referer, User-Agent, Content-Type, Authorization'});
    res.end(data);
  });
}


io.sockets.on('connection', function(socket) {
  //console.log(__dirname);
  fs.readFile(__dirname + '/../scripts/notifications.json', 'utf-8', function(err, data){
      if(err) throw err;
      socket.volatile.emit('notification', data);
  })

  try{
    fs.watch(__dirname + '/../scripts/notifications.json', function(curr, prev) {
      // on file change we can read the new xml
      fs.readFile(__dirname + '/../scripts/notifications.json','utf8', function(err, data) {
        if (err) throw err;
        // send the new data to the client
        socket.volatile.emit('notification', data);
      });
    });
  }
  catch(err){
    throw err;
  }

});

0 个答案:

没有答案
相关问题