당신은 항상 연결 beforeonload을 닫을 수 있습니다
,
$(window).on('beforeunload', function(){
socket.close();
});
그리고 당신은이 같은 자바 스크립트 오류 처리하는 웹 소켓의으로 onClose에 가입 할 수 있습니다 :
url = "ws://echo.websocket.org";
try {
socket = window['MozWebSocket'] ? new MozWebSocket(url) : new WebSocket(url);
socket.onopen = function(){
console.log('Socket is now open.');
};
socket.onerror = function (error) {
console.error('There was an un-identified Web Socket error');
};
socket.onmessage = function (message) {
console.info("Message: %o", message.data);
};
socket.onclose = function() {
console.info('Socket is now closed.');
}
} catch (e) {
console.error('Sorry, the web socket at "%s" is un-available', url);
}
setTimeout(function(){
socket.send("Hello World");
}, 1000);
바이올린 : http://jsfiddle.net/w5aAK/1/
을 답변 주셔서 감사합니다. 그게 내가 가지고있는 문제를 통과하게 만든거야. 이제 폼이 xhr 폴링이고 xhr 폴링이 된 다른 문제가 있습니다. xhr-polling stopm은 언제 어디로 갈 필요가 있는지 알려줍니다. xhr 폴링 후 연결 시간 초과가 열려있는 소켓을 찾을 수 없습니다. –