The default download the latest version of the Socket.io, the version number is 1.7.2, the support for IE8 is not good, anyway, in the IE8 to send and receive messages. On the internet to find a lot of information, can not solve the problem of IE8, collapse.
Finally, we have a version of 1.0.6 that you can use to support IE8:
Uninstalling Socket.io
NPM Uninstall Socket.io
Install 1.0.6 version of Socket.io
NPM install [email protected]
Some of the later versions do not have a one by one to go, under a 1.3.7 version, or can support the sending and receiving of messages, just found that IE8 in the closed window, the disconnect event cannot be triggered in real time.
Pit more than one, in addition to the Socket.io version, the client code, also need to use in the page header
<! DOCTYPE HTML >
To support IE8.
The following is the complete sample code
Service-Side App.js
varApp = require (' http '). Createserver (handler);varIO = require (' Socket.io ') (app);varFS = require (' FS ');varurl = require ("url"); App.listen (80);functionHandler (req, res) {varpathname =Url.parse (req.url). Pathname; if(Pathname = = "/") {Pathname= "/index.html"; } fs.readfile (__dirname+ Pathname, ' utf-8 ', function(err, data) {if(Err) {Res.writehead (500); returnRes.end (' Error loading ' +pathname); } res.writehead (200,{' content-type ': ' Text/html;charset=utf-8 '}); Res.end (data); });} Io.on (' Connection ',function(socket) {Console.log ("Send Message using:" +socket.conn.transport.name); Socket.on (' Message ',function(data) {Console.log (data); Socket.broadcast.emit (' Cast ', data); }); Socket.on (' Disconnect ',function(data) {Console.log (' Disconnect: ' +data); });});
Client code index.html
<!DOCTYPE HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Demo</title></Head><Body><Scriptsrc= "/socket.io/socket.io.js"></Script><Scriptsrc= "Jquery-1.11.3.min.js"></Script><Script> varSocket=Io.connect (); Socket.on ('Connect', function() {Socket.on ('cast', function(data) {$ ("#content"). Append ("<br/>" +data); }); });functionSend () {Socket.emit ('message', $("#msg"). Val ());}</Script><DivID= "Content"></Div><inputtype= "text"name= "MSG"ID= "MSG" /><inputtype= "button"name= "button"value= "button"OnClick= "Send ()"></Body></HTML>
Socket.io's support for IE8