无法使用 react-native-tcp-socket 从服务器接收响应

Not able to receive response from server using react-native-tcp-socket

描述

我正在使用 react-native-tcp-socket 通过我的 react-native 应用程序与服务器通信。当我使用 write() 向服务器发送数据时。我在 data 事件中没有得到响应。然而,当我使用 telnet 通过终端从服务器进行通信时,我得到了响应。有人可以指导我在这里做错了什么,或者为此建议一些其他包。

重现步骤

代码:

 client = TcpSocket.createConnection(
        {
          port: 7070,
          host: 'priceserver.attache.app'
        },
        () => {
          // sending data to server
          client.write('GETQUOTES');
        },
      );
      // socket event for - connection established
      client.on('connect', (on) => {
        console.log('connected to', on);
      });

      // socket event for - data received
      client.on('data', (data) => {
        console.log('Data ==>', data.toString());
      });

      // socket event for - error occured
      client.on('error', (error) => {
        console.log(error);
      });

      // socket event for - connection closed
      client.on('close', () => {
        console.log('Connection closed!');
      });

当前行为

除数据外的所有事件都正常

预期行为

我应该在数据事件的回调中获取数据

截图 这是终端的屏幕截图,我在其中收到回复。

相关信息

OS Ubuntu 20.04
react-native 0.63.2
react-native-tcp-socket ^4.5.5

刚刚看到问题。为任何需要这个的人自行回答。

我需要在发送到服务器的每个请求末尾添加一个回车符 return,所以它是这样的

client.write('GETQUOTES\r');

希望这对偶然发现这个问题的人有所帮助。