Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-12387

android websocket can't connect anymore

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Incomplete
    • None
    • None
    • cordova-android
    • Linux

    • Important

    Description

      Hi!

      Since my latest cordova update(6.5.0) I can't connect to my local websocket server. I've tried with echo.websocket.org without any success too. All is ok with "cordova run browser". Don't know where's problem(i've tried to downgrade but no success anymore...).

      EDIT:after many tries, websocket don't works with android android@6.1.1, succes works with android 5

      Sample code:

      <!DOCTYPE html>
      <meta charset="UTF-8">
      <meta http-equiv="Content-Security-Policy" content="default-src *; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'; img-src * data: 'unsafe-inline'; connect-src * 'unsafe-inline'; frame-src *;">
      <meta name="format-detection" content="telephone=no">
      <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
      <script type="text/javascript" src="cordova.js"></script>
      <script type="text/javascript" src="js/cordova_init.js"></script>
      <title>WebSocket Test</title>
      <script language="javascript" type="text/javascript">
      var wsUri = "ws://echo.websocket.org/";
      var output;
      function init()

      { output = document.getElementById("output"); testWebSocket(); }

      function testWebSocket()
      {
      websocket = new WebSocket(wsUri);
      websocket.onopen = function(evt)

      { onOpen(evt) }

      ;
      websocket.onclose = function(evt)

      { onClose(evt) }

      ;
      websocket.onmessage = function(evt)

      { onMessage(evt) }

      ;
      websocket.onerror = function(evt)

      { onError(evt) }

      ;
      }

      function onOpen(evt)

      { writeToScreen("CONNECTED"); doSend("WebSocket rocks"); }

      function onClose(evt)

      { writeToScreen("DISCONNECTED"); }

      function onMessage(evt)

      { writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>'); websocket.close(); }

      function onError(evt)

      { writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data); }

      function doSend(message)

      { writeToScreen("SENT: " + message); websocket.send(message); }

      function writeToScreen(message)

      { var pre = document.createElement("p"); pre.style.wordWrap = "break-word"; pre.innerHTML = message; output.appendChild(pre); }

      window.addEventListener("load", init, false);

      </script>

      <h2>WebSocket Test</h2>

      <div id="output"></div>

      Attachments

        Activity

          People

            Unassigned Unassigned
            alex72 Alexandre
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: