我们使用Node JS和Javascript使用套接字实现了聊天应用程序。 通常,聊天功能正常,但是当我们面对“套接字断开-传输错误”连续聊天时,“套接字断开-传输关闭” 错误消息和接收方无法发送消息。请提出解决方案
var io=require("Models/socket.io.2.0.js");
var socket =io.connect('Server URL', { query : "user_id="+USER_ID+);
socket.on('connect', function () {
console.log("socket connected");
console.log("socket id"+socket.id);
});
socket.on('disconnect', function(reason) {
console.log('Socket disconnected !'+reason);
if (reason === 'io server disconnect') {
socket.connect();
}
socket.open();
})
socket.on('new_message_recieved', function (text) {
//print received data in console log
console.log("Received Message"+JSON.stringify(text));
});