cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexandre (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CB-12387) android websocket can't connect anymore
Date Tue, 24 Jan 2017 19:02:27 GMT
Alexandre created CB-12387:
------------------------------

             Summary: android websocket can't connect anymore
                 Key: CB-12387
                 URL: https://issues.apache.org/jira/browse/CB-12387
             Project: Apache Cordova
          Issue Type: Bug
          Components: Android
         Environment: Linux
            Reporter: Alexandre


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...).

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>



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message