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: null is not an object (evaluating 'Sockets.connect') #103

Closed fabsi96 closed 3 years ago

fabsi96 commented 3 years ago

Description

After i installed the package like the readme, the socket always shows the error
TypeError: null is not an object (evaluating 'Sockets.connect')

Steps to reproduce

I had an existing installation of Nodejs, npm, npx, expo and yarn of this year but i also updated all components to the newest version and on other platforms. After installing Nodejs, npm and the expo-cli (as admin) and installing tcp-socket module via: npm install react-native-tcp-socket npm install react-native-tcp-socket --save yarn add react-native-tcp-socket ...the problem stays.

After the installation and creating a test project to run a sample tcp client, i got the mentioned error. I had worked on some react and react-native apps last couple weeks but this error makes me stupid. My test-code looks like this: (connect to server hosted on raspi in the same network)

import TcpSocket from 'react-native-tcp-socket';
...
const connOptions = {
        port: '2000',
        host: '192.168.1.140',
      };
      let client = TcpSocket.createConnection(connOptions, () => {

        client.destroy();
      });

I tried to take those steps to verify, that the linking is correct like the readme is telling, but that wont work for me. Also the existing report Issue with its recommended steps to solve this issue like 'gradlew clean' dont helped.

Can someone help me? Did i forgot something after i installed the package? Did I make mistakes?

Rapsssito commented 3 years ago

@fabsi96, I am sorry about your issue. However, if you are using Expo, you must eject your project before using any module with native code. Here is the documentation.

fabsi96 commented 3 years ago

@Rapsssito, Yes. I also thought that this is a problem and have tried it with the default way to create a project. After the project was created via 'npx react-native init myapp' i have imported tpc-socket via yarn add react-native-tcp-socket and also checked all linkings. After that i tried to start the app on a phone but everywhere i ran into the same issue..

Is that normal? Did i make a mistake? I would like to understand this "linking process".

Rapsssito commented 3 years ago

@fabsi96, it does not look normal, but take into account that linking the package manually is not required anymore with Autolinking.

However, make sure to clean your build folder from XCode if you are on iOS or run ./gradlew clean if you are on Android after installing the package.

fabsi96 commented 3 years ago

@Rapsssito Okay Yes I did that but did not work..

Rapsssito commented 3 years ago

@fabsi96, can you check if you can run the example code provided in the repository?

github-actions[bot] commented 3 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs.

fabsi96 commented 3 years ago

Hey. I have solved the problem by creating a new, raw RN project, because i first initialized the project with expo and the eject process had not work properly. I think that there was a problem with linking the packet into the project. It is also nice to verify, that the specific packet is linked correctly. Thats a thing that I had to learn while solving this problem.

Osric38 commented 3 years ago

I got same problem just after installing the package

fabsi96 commented 3 years ago

@Osric38 Try out to verify each installation process in detail. Its a bit difficult - i know - but after a couple times you should get that example project working. Verify that:
Your are NOT using expo in your first example project

Install the package savely

These were my issues i had to cope with and going bit deep as well. I hope you can get it to work!

gforien commented 3 years ago

@fabsi96, I am sorry about your issue. However, if you are using Expo, you must eject your project before using any module with native code. Here is the documentation.

I ran into the same issue. Thanks for the explanation 👍