knowledgecode / WebSocket-for-Android

Cordova/PhoneGap plugin that makes WebSocket available on Android
Apache License 2.0
143 stars 53 forks source link

ws.close then ws.create hangs #2

Closed rgillan closed 11 years ago

rgillan commented 11 years ago

Hi, When we pass a ws.close() to the plugin, it closes correctly (we see a disconnection on our server with code:1000 normal disconnection). When we try and re-establish a connection (ws.create) nothing hits the server and the plugin appears to hang. We think this was not the case prior to the last update adding the origin when it looks like you also refactored some of the code. Cheers Rob

knowledgecode commented 11 years ago

Hi, How do you re-establish a connection? The ws.create does not exist. The only way to re-establish a connection is to create a new instance.

rgillan commented 11 years ago

Sorry, meant was the wrong reference. When we call close to close the WebSocket, it indeed closes. When we try to create a new connection (wsSocket = new plugins.WebSocket(config[0], config[1], config[2]);) it hangs and never establishes the new WebSocket. We never see the onOpen response.

Cheers

On 10/05/2013, at 11:57 PM, knowledgecode wrote:

Hi, How do you re-establish a connection? The ws.create does not exist. The only way to re-establish a connection is to create a new instance.

— Reply to this email directly or view it on GitHub.

rgillan commented 11 years ago

Have you been able to replicate our problem? Let us know if we can help with further testing,

Cheers Rob

knowledgecode commented 11 years ago

No, I haven't. Would you show me your code snippet? If that helps, when you re-establish, are the parameters the same as first time?

rgillan commented 11 years ago

Here's our Javascript that talks to the module:

config is an array containing url, subprotocol, origin

var wsSocket = null; dzhonWS = function () {};

dzhonWS.prototype.wsCreate = function (config) { if (!wsSocket) { wsSocket = new plugins.WebSocket(config[0], config[1], config[2]); console.log('wsCreate:' + wsConfig); wsSocket.onopen = function () { console.log('onopen'); onWsOpen(); }; wsSocket.onmessage = function (message) { console.log('onmessage:' + message); onWsMessage(JSON.parse(message)); }; wsSocket.onerror = function (error) { console.log('onerror'); onWsError(error); }; wsSocket.onclose = function () { console.log('onclose'); onWsClose(); }; } };

dzhonWS.prototype.wsSend = function (message) { wsSocket.send(message[0]); };

dzhonWS.prototype.wsClose = function () { wsSocket.close(); };

rgillan commented 11 years ago

wsSocket is supposed to be closed in the onWsClose method called, will check and get back to you. Might be the culprit.

knowledgecode commented 11 years ago

Is the wsSocket set to null in the onWsClose method? I think that just closing the wsSocket will not work the following the if sentence.

if (!wsSocket) { wsSocket = new plugins.WebSocket(config[0], config[1], config[2]); console.log('wsCreate:' + wsConfig); wsSocket.onopen = function () { console.log('onopen'); onWsOpen(); };

rgillan commented 11 years ago

Will confirm in the morning, thanks for your help with all this.

rgillan commented 11 years ago

We've confirmed that setting wsSocket to null in the onClose method resolves this issue. Thanks for all your help