Rapsssito / react-native-tcp-socket

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

TypeError: undefined is not an object (evaluating '_reactNativeTcpSocket.TcpSocket.createConnection') #135

Closed Klairm closed 2 years ago

Klairm commented 2 years ago

Description

When creating a connection I'm getting the error TypeError: undefined is not an object (evaluating '_reactNativeTcpSocket.TcpSocket.createConnection') and I'm not sure how to debug this properly to see where's the error originated

Or code:

const client = TcpSocket.createConnection(
    { port: Port, host: IP },
    () => {
    client.write(Payload);
        client.destroy();
    });

    client.on("error", function (error) {
         console.log(error);
    });
    client.on("close", function () {
          console.log("Connection closed!");
    });

Relevant information

OS Developing for Android using Linux
react-native react-native@0.64.3
react-native-tcp-socket react-native-tcp-socket@5.5.0

I'm using Expo idk if that's relevant

Klairm commented 2 years ago

So if anyone comes here, first of all I tried to "import" using

const net = require('react-native-tcp-socket');

And that gave another error

`TypeError: null is not an object (evaluating 'Sockets.connect')`

So after someone suggested to me on Reddit, I had to eject the code with expo eject then rebuild the app using expo run:android and that worked!

So if anyone's struggling with this might wanna try that.