I add this(see below) in the chat example to send a disconnect from the client.
You have to use xhr-polling for this test
var connectedUrl = "";
socket.on('connect', function () {
$('#chat').addClass('connected');
console.log(this.socket.transports);
$.each(this.socket.transports, function(index, item){
$("#transport").append(new Option(item, item));
});
console.log(this.socket.options.resource);
console.log(this.socket.transport.name);
console.log(this.socket.sessionid);
console.log(io.protocol);
//connectedUrl = document.location.protocol + "://" + document.location.host + "/" + this.socket.options.resource + "/" + io.protocol + "/" + this.socket.transport.name + "/" + this.socket.sessionid;
connectedUrl = "/" + this.socket.options.resource + "/" + io.protocol + "/" + this.socket.transport.name + "/" + this.socket.sessionid;
var getDisconnectURL = connectedUrl + "/?t="+ +new Date + "&disconnect";
console.log(getDisconnectURL);
});
$("#manualDisconnectGet").bind("click", function(){
var getDisconnectURL = connectedUrl + "?t="+ +new Date + "&disconnect";
$.get(getDisconnectURL, function(data) {
//$('.result').html(data);
alert('Load was performed.' +data);
});
});
$("#manualDisconnectPost").bind("click", function(){
var getDisconnectURL = connectedUrl;
$.post(getDisconnectURL, "0:::", function(data) {
alert("Data Loaded: " + data);
});
});
Force Disconnect with GET
<div id="manualDisconnectPost">Force Disconnect with Post</div>
</div>
manualDisconnectGet {
height: 30px;
left: 0;
top: 0;
text-align: center;
width: 150px;
font: 15px Georgia;
color: #666;
}
manualDisconnectPost {
height: 30px;
left: 0;
top: 0;
text-align: center;
width: 150px;
font: 15px Georgia;
color: #666;
}
and I received that in my log if a try with a GET
1322726785 (3379512509903672): Start 'close_timer' (15)
1322726785 (3379512509903672): Event 'on_write'
1322726785 (3379512509903672): Staging '5:::{"args":[],"name":"disconnect"}'
1322726790 (3379512509903672): Send heartbeat
1322726790 (3379512509903672): Stop 'close_timer'
1322726790 (3379512509903672): Start 'close_timer' (15)
1322726790 (3379512509903672): Event 'on_write'
1322726790 (3379512509903672): Staging '2::'
1322726793 (2664053128490294): Send heartbeat
1322726793 (2664053128490294): Stop 'close_timer'
1322726793 (2664053128490294): Start 'close_timer' (15)
1322726793 (2664053128490294): Event 'on_write'
1322726793 (2664053128490294): Staging '2::'
1322726800 (3379512509903672): Send heartbeat
... it doesn't stop.
with a POST I'll never received a disconnect event.
1322726905 (2888142389001222): Start 'close_timer' (15)
1322726908 (2888142389001222): Received '0:::'
1322726908 (2888142389001222): Stop 'close_timer'
1322726908 (2888142389001222): Start 'close_timer' (15)
127.0.0.1 - - [01/Dec/2011:00:08:28 -0800] "POST /socket.io/1/xhr-polling/2888142389001222 HTTP/1.1" 200 1 "http://localhost:5000/chat.html" "Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
1322726913 (2664053128490294): Send heartbeat
1322726913 (2664053128490294): Stop 'close_timer'
1322726913 (2664053128490294): Start 'close_timer' (15)
1322726913 (2664053128490294): Event 'on_write'
1322726913 (2664053128490294): Staging '2::'
1322726915 (2888142389001222): Send heartbeat
1322726915 (2888142389001222): Stop 'close_timer'
1322726915 (2888142389001222): Start 'close_timer' (15)
1322726915 (2888142389001222): Event 'on_write'
1322726915 (2888142389001222): Writing '2::'
1322726915 (2888142389001222): Emitting 'on_write'
1322726915 (2888142389001222): State 'reconnecting'
1322726915 (2888142389001222): Stop 'close_timer'
1322726915 (2888142389001222): Start 'reconnect_timer' (15)
1322726915 (2888142389001222): Received '2::'
1322726915 (2888142389001222): Stop 'close_timer'
1322726915 (2888142389001222): Start 'close_timer' (15)
127.0.0.1 - - [01/Dec/2011:00:08:35 -0800] "POST /socket.io/1/xhr-polling/2888142389001222?t=1322726915458 HTTP/1.1" 200 1 "http://localhost:5000/chat.html" "Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
1322726915 (2888142389001222): State 'reconnected'
1322726915 (2888142389001222): Stop 'reconnect_timer'
1322726915 (2888142389001222): Emitting 'on_reconnect'
1322726915 (2888142389001222): Start 'close_timer' (15)
1322726923 (2664053128490294): Send heartbeat
1322726923 (2664053128490294): Stop 'close_timer'
1322726923 (2664053128490294): Start 'close_timer' (15)
1322726923 (2664053128490294): Event 'on_write'
1322726923 (2664053128490294): Staging '2::'
1322726925 (2888142389001222): Send heartbeat
1322726925 (2888142389001222): Stop 'close_timer'
1322726925 (2888142389001222): Start 'close_timer' (15)
1322726925 (2888142389001222): Event 'on_write'
1322726925 (2888142389001222): Writing '2::'
1322726925 (2888142389001222): Emitting 'on_write'
1322726925 (2888142389001222): State 'reconnecting'
1322726925 (2888142389001222): Stop 'close_timer'
I add this(see below) in the chat example to send a disconnect from the client.
You have to use xhr-polling for this test
var connectedUrl = "";
socket.on('connect', function () {
$('#chat').addClass('connected');
console.log(this.socket.transports);
});
$("#manualDisconnectGet").bind("click", function(){
var getDisconnectURL = connectedUrl + "?t="+ +new Date + "&disconnect";
manualDisconnectGet {
height: 30px;
left: 0;
top: 0;
text-align: center;
width: 150px;
font: 15px Georgia;
color: #666;
}
manualDisconnectPost {
height: 30px;
left: 0;
top: 0;
text-align: center;
width: 150px;
font: 15px Georgia;
color: #666;
}
and I received that in my log if a try with a GET
1322726785 (3379512509903672): Start 'close_timer' (15)
1322726785 (3379512509903672): Event 'on_write'
1322726785 (3379512509903672): Staging '5:::{"args":[],"name":"disconnect"}'
1322726790 (3379512509903672): Send heartbeat
1322726790 (3379512509903672): Stop 'close_timer'
1322726790 (3379512509903672): Start 'close_timer' (15)
1322726790 (3379512509903672): Event 'on_write'
1322726790 (3379512509903672): Staging '2::'
1322726793 (2664053128490294): Send heartbeat
1322726793 (2664053128490294): Stop 'close_timer'
1322726793 (2664053128490294): Start 'close_timer' (15)
1322726793 (2664053128490294): Event 'on_write'
1322726793 (2664053128490294): Staging '2::'
1322726800 (3379512509903672): Send heartbeat
... it doesn't stop.
with a POST I'll never received a disconnect event.
1322726905 (2888142389001222): Start 'close_timer' (15)
1322726908 (2888142389001222): Received '0:::'
1322726908 (2888142389001222): Stop 'close_timer'
1322726908 (2888142389001222): Start 'close_timer' (15)
127.0.0.1 - - [01/Dec/2011:00:08:28 -0800] "POST /socket.io/1/xhr-polling/2888142389001222 HTTP/1.1" 200 1 "http://localhost:5000/chat.html" "Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
1322726913 (2664053128490294): Send heartbeat
1322726913 (2664053128490294): Stop 'close_timer'
1322726913 (2664053128490294): Start 'close_timer' (15)
1322726913 (2664053128490294): Event 'on_write'
1322726913 (2664053128490294): Staging '2::'
1322726915 (2888142389001222): Send heartbeat
1322726915 (2888142389001222): Stop 'close_timer'
1322726915 (2888142389001222): Start 'close_timer' (15)
1322726915 (2888142389001222): Event 'on_write'
1322726915 (2888142389001222): Writing '2::'
1322726915 (2888142389001222): Emitting 'on_write'
1322726915 (2888142389001222): State 'reconnecting'
1322726915 (2888142389001222): Stop 'close_timer'
1322726915 (2888142389001222): Start 'reconnect_timer' (15)
1322726915 (2888142389001222): Received '2::'
1322726915 (2888142389001222): Stop 'close_timer'
1322726915 (2888142389001222): Start 'close_timer' (15)
127.0.0.1 - - [01/Dec/2011:00:08:35 -0800] "POST /socket.io/1/xhr-polling/2888142389001222?t=1322726915458 HTTP/1.1" 200 1 "http://localhost:5000/chat.html" "Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
1322726915 (2888142389001222): State 'reconnected'
1322726915 (2888142389001222): Stop 'reconnect_timer'
1322726915 (2888142389001222): Emitting 'on_reconnect'
1322726915 (2888142389001222): Start 'close_timer' (15)
1322726923 (2664053128490294): Send heartbeat
1322726923 (2664053128490294): Stop 'close_timer'
1322726923 (2664053128490294): Start 'close_timer' (15)
1322726923 (2664053128490294): Event 'on_write'
1322726923 (2664053128490294): Staging '2::'
1322726925 (2888142389001222): Send heartbeat
1322726925 (2888142389001222): Stop 'close_timer'
1322726925 (2888142389001222): Start 'close_timer' (15)
1322726925 (2888142389001222): Event 'on_write'
1322726925 (2888142389001222): Writing '2::'
1322726925 (2888142389001222): Emitting 'on_write'
1322726925 (2888142389001222): State 'reconnecting'
1322726925 (2888142389001222): Stop 'close_timer'