Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-native-tcp-socket connect() not working #201

Open
Tzr512 opened this issue Nov 4, 2024 · 1 comment
Open

react-native-tcp-socket connect() not working #201

Tzr512 opened this issue Nov 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Tzr512
Copy link

Tzr512 commented Nov 4, 2024

Error in connection line: "Sockets . connect( this . _id , customOptions . host , customOptions . port , customOptions) ;"
Error msg: Cannot read properties of undefined (reading 'connect')
stack:
connect --> node_modules/react-native-tcp-socket/src/Socket.js:167:17
createConnection --> node_modules/react-native-tcp-socket/src/index.js:50:22

Steps to reproduce the behavior:

  1. Create app -> npx create-expo-app@latest nameApp
  2. Install lib -> npm install --save react-native-tcp-socket
  3. Configure library -> https://www.npmjs.com/package/react-native-tcp-socket
  4. Code en index.tsx:
    `const options = {
    port: 8888,
    host: '192.168.0.202',
    ///localAddress: '192.168.0.11',
    localAddress: 'localhost',
    tls: false,
    reuseAddress: true,
    // localPort: 20000,
    // interface: "wifi",
    };

// Create socket
const client = TcpSocket.createConnection(options, () => {
// Write on the socket
client.write('Hello server!');
alert('Say Hello!!!');

// Close socket
client.destroy();

});

client.on('data', function(data) {
alert('message was received' + data);
});

client.on('error', function(error) {
alert(error);
});

client.on('close', function(){
alert('Connection closed!');
});`

When I launch the application 'npm run web' or 'npm run android' I get this error

On the other side I have an ESP32 prepared to receive TCP connections. From a native application in Android I connect directly using Socket. The IP and port I use is the same as the native application, in 'localAddress' I try with the real IP within the wifi (192.168.0.11), localhost and 127.0.0.1. It always shows the same error.

Esp32 never receives data (if I use socket.io Esp32 does receive data but the connection is constantly reset). Is this the typical error when wrong connection data is entered?

I am testing on Android and web

OS -> Mac Big Sur
react-native -> latest
react-native-tcp-socket -> latest

@Tzr512 Tzr512 added the bug Something isn't working label Nov 4, 2024
@0XiSi
Copy link

0XiSi commented Nov 22, 2024

same problem same setup, but i got a esp8266 waiting. lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants