Rapsssito / react-native-tcp-socket

React Native TCP socket API for Android, iOS & macOS with SSL/TLS support.
MIT License
315 stars 80 forks source link

Not able to receive response from server #95

Closed n4beel closed 3 years ago

n4beel commented 3 years ago

Description

I am using this package to communicate with a server. When I am using write() to send data to a server. I am not getting response in the data event. Whereas, when I am using telnet to communicate from the server through terminal I am getting the response.

Steps to reproduce

code:

 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!');
      });

Current behavior

all events except data are working

Expected behavior

I should get data in the data event's callback

Screenshots Here is a screenshot of terminal, in which I am getting response. Screenshot from 2021-01-15 12-23-15

Relevant information

OS Linux 20.04
react-native 0.63.2
react-native-tcp-socket ^4.5.5
Rapsssito commented 3 years ago

@n4beel, I see you are using telnet. react-native-tcp-socket only provides a TCP socket API, any other protocol built on top of TCP must be implemented by the user. Take a look at telnet-client for NodeJS, you might be able to adapt it to work with this library.

n4beel commented 3 years ago

Thanks for the response, you saved my time as I would have kept on trying to connect using this package.

n4beel commented 3 years ago

@Rapsssito your library worked for me. I just needed to append CR + LF (\r\n) to the text I was sending and I got the response.