Skip to content

websocket.onopen is not called #8

@punj

Description

@punj

Hi!

I tried to use this plugin since last 2 days with cordova version 3.3.0. But, unfortunately
websocket.open method is not calling somehow. I tested on Android device Samsung Galaxy SDUOS of android version 4.0.4.

Let me to write the code which I have implemented as under where init method is called ondeviceready:

var wsUri = "ws://echo.websocket.org/";

    var output;
    function init() {
    console.log('init');
        output = document.getElementById("output");
        testWebSocket();
    }
    function testWebSocket() {
    console.log('testWebSocket');
        websocket = new WebSocket(wsUri);
        websocket.onopen = function(evt) {
        console.log('in onopen');       
            onOpen(evt)
        };

        websocket.onmessage = function(evt) {
            onMessage(evt)
        };
        websocket.onerror = function(evt) {
            onError(evt)
        };
    }
    function onOpen(evt) {
        writeToScreen("CONNECTED");
        doSend("WebSocket rocks");
    }

    function onMessage(evt) {
       console.log('RESPONSE: ' + evt.data);
        websocket.close();
    }
    function onError(evt) {
        console.log('ERROR:' + evt.data);
    }
    function doSend(message) {   
        websocket.send(message);
    }

Hope this will help you to identify if any mistake is found.

Thanks in advance..!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions