在IE8和9上的socket.io的问题 [英] problems with socket.io on IE8 and 9

查看:199
本文介绍了在IE8和9上的socket.io的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Socket.io在每个平台上都能正常工作,除了IE8和9,这是一个客户端要求。你能帮我解决这个问题吗?



我一直在读所有类似的问题,但大多数解决方案,我发现到现在不能解决这个问题在IE8。 / p>

这里是结构:



服务器端

  var ip ='xxx.xxx.xxx.xxx'; 
var ipPort ='8081';

var app = require('http')。createServer(handler);
var io = require('socket.io')(app);
var fs = require('fs')

app.listen(ipPort,function(){
//console.log('Listening at:http: + ip +':'+ ipPort +'');
});

//io.set('transports',['websocket','flashsocket','htmlfile','xhr-polling','jsonp-polling']);

函数处理程序(req,res){
fs.readFile(__ dirname +'/test.html',
function(err,data){
if err){
res.writeHead(500);
return res.end('Error loading index.html');
}

res.writeHead );
res.end(data);
});
}

客户端

 < html> 
< body>
< / body>
< script src =/ socket.io/socket.io.js\"> ;</script>
< script>
alert(hi);

// var socket = io.connect('xxx.xxx.xxx.xxx:8081',{transports:'jsonp-polling');
var socket = io.connect(''xxx.xxx.xxx.xxx:8081',{secure:true});

socket.on('news',function(data){
alert(hello data:+ data [0]);
socket.emit('my other event',{my:data});
});

socket.on('connect',function(){
alert(hello socket);
});

< / script>
< / html>

我根本没有错误,只是没有回应..我放置了一个警报('news'),并没有得到任何反馈,但是我添加了socket.on('connect'),并放置了alert()里面,它弹出来了!



希望有人在那里通过这个问题之前,解决它。
我在win7和节点(v0.10.30)socket.io(v1.0.6)
非常感谢所有的帮助。

解决方案

我发现这个问题的一个解决方案是安装add express到服务器端;
和所有神奇的作品!
(npm install express)





想知道我们是否都需要安装快速以避免这些问题.. mmmhh!



编辑:
显然在客户端代码内还有两个其他问题:



我添加了<!DOCTYPE html> ,并将socket.io外部脚本链接和代码移动到标记的末尾。所有问题都消失了。


Socket.io works perfectly on every platform except IE8 and 9, which is a client requirement. could you guys help with this issue?

i've been reading all similar issues but most of the solutions i found till now can't solve this problem on IE8.

here's the structure:

SERVER-SIDE

var ip = 'xxx.xxx.xxx.xxx';
var ipPort = '8081';

var app = require('http').createServer(handler);
var io = require('socket.io')(app);
var fs = require('fs')

app.listen(ipPort, function() {
//console.log('Listening at: http://'+ ip +':'+ ipPort +'');
});

//io.set('transports', ['websocket','flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']);

function handler (req, res) {
 fs.readFile(__dirname + '/test.html',
  function (err, data) {
    if (err) {
    res.writeHead(500);
    return res.end('Error loading index.html');
    }

  res.writeHead(200);
  res.end(data);
 });
}

CLIENT-SIDE

<html>
<body>
</body>
   <script src="/socket.io/socket.io.js"></script>
   <script>
    alert("hi");

   //var socket = io.connect('xxx.xxx.xxx.xxx:8081',{transports:'jsonp-polling');
   var socket = io.connect(''xxx.xxx.xxx.xxx:8081',{secure: true});

   socket.on('news', function (data) {
    alert("hello data:"+data[0]);
   socket.emit('my other event', { my: data });
   });  

   socket.on('connect', function () {
     alert("hello socket");
   });

   </script>
</html>

i get no errors at all, just no response.. i placed an alert() on socket.on('news') and doesn't get any feedback, BUT THEN i added socket.on('connect') and placed the alert() inside and it pops up!!

hope there's someone out there that pass through this issue before and solve it. I'm on win7 and node(v0.10.30) socket.io(v1.0.6) thanks very much for all the help.

解决方案

the one solution i found to this problem was to install add express to the server-side; and all miraculously works! (npm install express)

wondering if we all need to install express in order to avoid these issues.. mmmhh!

EDIT: apparently there were two other issues inside the code in the client-side:

i added <!DOCTYPE html> at the header of the page, and moved the socket.io external script link and code to the end of the tag. and all problems were gone.

这篇关于在IE8和9上的socket.io的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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