Closed Netpolice closed 9 years ago
I MADE IT.... in the phonegap-websocket.js
reconnect: function() {
this.readyState = WebSocket.CONNECTING;
cordova.exec(
function (event) {
socket._handleEvent(event);
},
function (event) {
socket._handleEvent(event);
}, "WebSocket", "connect", [ this.socketId, this.url, this.options ]);
},
in the client js
socket.onclose = function(msg) {
if(connected == 1) {
connected = 0;
socket.reconnect();
} else {
setTimeout(function() {
socket.reconnect();
}, 1500);
}
};
This looks like a good approach.
If the server disconnected, how to re-connect? If calling WebSocket("ws://xxx.xxxx.xxx.xx:8080"); again, the onopend not fired. Thanks.