cordova - Chrome Sockets TCP 正在发送数据但未接收数据
问题描述
我在我的 Ionic 应用程序中使用了 Cordova 的 Chrome Sockets TCP 插件。我可以轻松地将数据发送到我的服务器,但我无法接收任何内容,无论我做什么,onReceive 事件都不会触发。send() 方法工作得很好,但 onReceive 甚至没有运行,我知道这是因为我在控制台中看不到任何东西。我看过很多例子,但没有任何例子有帮助。我的问题可能是什么?我的代码如下。(说 this.str2ab(req) 的行是一个函数调用,它将我的名为 req 的字符串更改为 arrayBuffer)
//Connects to the server
connect() {
(<any>window).chrome.sockets.tcp.create({}, (createInfo) => {
this.id = createInfo.socketId;
(<any>window).chrome.sockets.tcp.connect(this.id, this.ip, this.port, (result) => {
console.log("Connected to the server " + result);
});
});
};
//Function for sending and receiving data
getStatus() {
// Send data
(<any>window).chrome.sockets.tcp.send(this.id, this.str2ab(this.req),
(resultCode) => {
console.log("Data sent to new TCP client connection.")
console.log(JSON.stringify(resultCode))
});
// Start receiving data
(<any>window).chrome.sockets.tcp.onReceive.addListener(() => {
console.log("This is the received object")
console.log("Data received")
});
(<any>window).chrome.sockets.tcp.setPaused(this.id, false);
};
解决方案
推荐阅读
- visit-llnl - 如何在访问绘图程序上显示实际轴数值而不是从 0.0 到 1.0 的分数?
- javascript - 停止使用在反应应用程序中重新订阅的事件源
- android - 扫描条码时,如果同时出现两个条码,应该返回错误
- protractor - 如何使用 jamine/protractor 为诱惑报告添加自定义步骤或描述
- python - 如何阻止除块之外的多个错误被捕获?
- web-services - utf8字符串制动一种实现Web服务功能的方式
- mysql - 如何使用左连接减去值的总和?
- logstash - 使用 jdbc logstash 插件从 mysql db 获取数据时出错
- android - 出现错误尝试在空对象引用上调用虚拟方法“void android.widget.TextView.setText(java.lang.CharSequence)”
- python - 如何向 IGMP 设备发送 UDP 数据报?