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

Handle connection refused error #89

Closed Fedour57 closed 3 years ago

Fedour57 commented 3 years ago

Description

Hello, I'm trying to handle aconnection refused error, if I try to connect to a server that doesn't exist, my app crash.

Steps to reproduce

Code:

try
{
    var client = net.createConnection({ port: 49500, host: "255.0.0.0",timeout:1000 })
}
catch (error)
{
    console.log(error)
}

OR

 var client = net.createConnection({ port: 49500, host: "255.0.0.0",timeout:1000 })
 .then(val =>
{
    console.log("connected")
}           
).catch(error => {
    console.log(error)
})

Current behavior

The app crash when the client can not connect to the server.

Expected behavior

The try catch block should handle the error

Relevant information

react-native 0.63.3
react-native-tcp-socket 4.5.4
Rapsssito commented 3 years ago

@Fedour57, thanks for your feedback! Please, take a look at #53, it might be your problem. You could try some of the workarounds commented over there.