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

Handle connection refused error #114

Open
Fedour57 opened this issue Dec 9, 2020 · 2 comments
Open

Handle connection refused error #114

Fedour57 opened this issue Dec 9, 2020 · 2 comments

Comments

@Fedour57
Copy link

Fedour57 commented Dec 9, 2020

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

I've try something like this:

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

and also:

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

But the App still continue to crash with the Connection Refused Exception

@BoyZhouY
Copy link

BoyZhouY commented Jan 7, 2021

Is it solved?

@taha200
Copy link

taha200 commented Jun 3, 2022

Hello developers, I have just recently used the react-native TCP and I encountered with connection refused error while creating the connection if the server is closed, how I handled it, I used net.connect() method rather than create connection, then error event handle the connection refused error, I am pasting the code here so you can see it, Thank you.
`const client = await net.connect(5000,data[i].ipdata_ip,()=>{
client.write(JSON.stringify({
tableNum: tab,
time: Moment(new Date()).format('MM-DD-YYYY hh:mm:ss A')
}));
client.destroy()

})
client.on('error',(error)=>{
alert(Configuration kitchen error at screen ${data[i].ipdata_ip})
})`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants