【发布时间】:2016-12-14 20:02:32
【问题描述】:
试图让 WebSocket 在 ionic2 Android 应用程序中工作。 在浏览器模式下工作正常。
我安装了https://github.com/knowledgecode/WebSocket-for-Android 并按照所有说明进行操作: - 安装科尔多瓦插件白名单 - 设置内容安全策略 (CSP) - 设置 config.xml:
<access origin="*"/>
<allow-intent href="ws://*/*:*"/>
<allow-intent href="wss://*/*:*"/>
但是当我使用 ionic run android
进行测试时,没有连接到我的服务器connect(){
this.ws = new WebSocket("ws://192.168.178.170:8000");
this.ws.onopen = () => {
console.log('open');
};
this.ws.onmessage = (event) => {
console.log('new message: ' + event.data);
this.messages.push(event.data);
};
this.ws.onerror = () => {
console.log('error occurred!');
};
this.ws.onclose = (event) => {
console.log('close code=' + event.code);
this.connect();
};
我错过了什么吗?
【问题讨论】:
标签: javascript android ionic-framework websocket ionic2