Software Archive
Read-only legacy content
17061 Discussions

Cordova + Crosswalk + websocket issue

klevis
Beginner
635 Views

Hello there, 

I am having trouble connecting through websocket on a webapp. If I test my websocket connection on my desktop on chrome it works fine. When I try to test the same application, by debugging on the phone or even building the apk, it does not work. I have tried the stable and beta versions of crosswalk but it still wont work. Basically the connection cannot be established(there's no handshake) and socket.onclose gets called. I am testing on Galaxy S4 which has android 4.4.2.
I am using the crosswalk blank project as a template for my project. 
This should be fairly straightforward, am I missing something ?
Is there a working example for crosswalk and websocket somewhere ?

document.addEventListener("deviceready", onDeviceReady, false);
 document.addEventListener("app.Ready", onAppReady, false);

function onAppReady() {
            if (navigator.splashscreen && navigator.splashscreen.hide) { // Cordova API detected
                navigator.splashscreen.hide();
            }
            if (window.intel && intel.xdk && intel.xdk.device) { // Intel XDK device API detected, but...
                if (intel.xdk.device.hideSplashScreen) // ...hideSplashScreen() is inside the base plugin
                    intel.xdk.device.hideSplashScreen();
            }
        }
 
function onDeviceReady() {

if ("WebSocket" in window) {
        var socket = new WebSocket('ws://myserverIP:8888');
        socket.onopen = function (event) {
            alert("open" + event)
        };

        socket.onmessage = function (event) {
            alert("message " + event);
        }

        socket.onclose = function (event) {
            alert("onclose " + event);
        }
      
    } else {

        alert("no websocket");
    }

}

 

0 Kudos
1 Reply
klevis
Beginner
635 Views

I was able to fix the issue. The problem was with some configuration on the server instance and allowing all the connections to come through port 8888. Websocket connection is working fine on crosswalk. Thanks

0 Kudos
Reply