server.js
<pre> var app = require(‘express’)() , server = require(‘http’).createServer(app) , io = require(‘socket.io’).listen(server,{log:false});
server.listen(888);
app.get(’/’, function (req, res) { res.sendfile(__dirname + ‘/index.html’); });
io.sockets.on(‘connection’, function (socket) { console.log('connection '+new Date()); socket.emit(‘news’, { hello: ‘world’ }); socket.on(‘my other event’, function (data) { console.log(data); }); socket.on(‘disconnect’, function () { console.log('user disconnected '+new Date()); }); }); </pre> express 3.0.6 socket.io 0.9.13
client.html
<pre> <script src=“http://localhost:888/socket.io/socket.io.js”></script> <script>
if (/Firefox/\s/.test(navigator.userAgent)){ var socket = io.connect(“http://localhost:888”,{transports:[‘xhr-polling’]}); } else if(/MSIE (\d+.\d+);/.test(navigator.userAgent)){ var socket = io.connect(“http://localhost:888”,{transports:[‘jsonp-polling’]}); } else { var socket = io.connect(“http://localhost:888”); }
socket.on(‘news’, function (data) { //console.log(data); document.write(data.hello); socket.emit(‘my other event’, { my: ‘data’ }); }); </script> </pre>
客户端是apache+php的,在google浏览器一切正常,刷新和关闭都正常 但是在ie和ff能连接上并正常通信,但是在1分钟之内会自动触发disconnect事件,反而正常退出或刷新却不能触发disconnect事件,混乱了…求高手帮忙解答!!!
socket.io版本改成0.8.4的后,ie正常了chrome又不行了。。。 于是将socket.io0.9.13 transports 下的jsonp-polling.js和http-polling.js替换成0.8.4的,他居然就行了 太TM神奇了,完全无语了
好吧…socket.io 0.9.4 之后的版本都不行了,这东西怎么越更新越坑了呢