HarmonyOS socket tcp连接报错?

socket tcp连接报错,已经确认地址和端口是正确的。

error:{"code":2301115,"message":"Operation in progress"}
/**
 * 连接服务器
 */
public
startTcpSocketConnect() {
  //连接服务器的地址和端口
  connectAddress: socket.NetAddress = {
    address: YiZhiCameraSocket.IP,
    family: 1,
    port: 5000
  }
  //开始连接
  let tcpConnect: socket.TCPConnectOptions = {} as socket.TCPConnectOptions;
  tcpConnect.address = this.connectAddress;
  tcpConnect.timeout = CONNECT_TIMEOUT;

  this.log('SocketDemo tcpSocket.connect info:' + JSON.stringify(tcpConnect));

  tcpSocket.connect(tcpConnect, (err: BusinessError) => {
    // {"code":2301115,"message":"Operation in progress"}
    this.log('SocketDemo tcpSocket.connect error:' + JSON.stringify(err));
    if (err) {
      this.log('SocketDemo 连接服务器失败');
      return;
    }
    this.log('SocketDemo 连接服务器成功,准备执行上线操作');
  });
}
阅读 447
1 个回答

使用tcpsocket返回2301115错误码是Linux内核错误码,可检查下服务端或请求端口能否正常使用。

logo
HarmonyOS
子站问答
访问
宣传栏