problems with socket.io on IE8 and 9

为君一笑 提交于 2019-12-04 18:29:27

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.

I noticed problems with using express and socket.io together (possibly; not 100% sure of the real cause) with IE8, if you reload a webpage with a socket on it, sometimes the new socket won't funtion properly

It would manifest by the socket server losing packets, and occasionally with express not loading web pages either; restarting the server was needed to fix this. It was easy to observe just be rapidly reloading a web page with a socket.io client on it which tried to send messages back and forth (our testing framework does this).

I suspect express since socket.io seems to hook into express, and loading the webpage itself seemed to have issues occasionally.

While investigating I noticed sockets were not disconnecting automatically on page unload and would instead seem to timeout on the server side to disconnect.

Explicitly disconnecting this way seems to fix it (translate to your favorite framework as needed):

$(window).on("beforeunload", function() {
    socket.disconnect();
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!