首页 > 解决方案 > 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);
};

标签: cordovagoogle-chromesocketsionic-framework

解决方案


推荐阅读