cordova websocket onready for android

时间:2014-09-28 22:30:35

标签: javascript cordova websocket

祝你好运, 我尝试了几个websocket插件,但没有一个适合我。 我无法知道什么是错的,因为当我在浏览器中尝试代码时,它可以成功运行但是在构建apk之后,没有任何反应。 我检查了config.xml,权限和插件的配置。 我猜Jelly beans inbrowser不支持websocket(我们已经知道),但即使在插件中也是如此?只是一个猜测。 我使用jwebsocket作为websocket服务器。 cordova版本3.5.0 请告诉我我的代码中有什么问题

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <meta name="msapplication-tap-highlight" content="no" />
        <title>Hello World</title>
<script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // device APIs are available
    function onDeviceReady() {
       var ws = new WebSocket('ws://192.168.1.6:8787/');
ws.onmessage = function () {
  alert('a message was recieved');
};
ws.onopen = function () {
ws.send('I just connected!');
};
    }
 </script>
<script type="text/javascript" src="websocket.js"></script>
  </head>
  <body onload="onLoad()">
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>
</body>
</html>

0 个答案:

没有答案