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

onClose event does not fire on connection lost #30

Closed
micahbule opened this issue Feb 27, 2020 · 1 comment
Closed

onClose event does not fire on connection lost #30

micahbule opened this issue Feb 27, 2020 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@micahbule
Copy link

Description

onClose event doesn't fire when a TCP client loses WiFi

Steps to reproduce

Steps to reproduce the behavior:

  1. Instantiate a TCP Server on device1.
  2. Instantiate a TCP Client on device2 and connect to device1.
  3. Turn off WiFi for device2.

Current behavior

Client's socket in the TCP server is still connected.

Expected behavior

Client's socket in the TCP server must be disconnected.

Relevant information

OS ubuntu 18.04
react-native 0.61.4
react-native-tcp-socket 3.3.1
@micahbule micahbule added the bug Something isn't working label Feb 27, 2020
@Rapsssito
Copy link
Owner

Rapsssito commented Feb 27, 2020

@micahbule, I am sorry, but TCP does not provide an explicit disconection event, since it is an idle protocol. You can find more information on this article about half-open connection:

TCP does have acknowledgments for data, so when one side sends data to the other side, it will receive an acknowledgment if the connection is stil active (or an error if it is not). Thus, broken connections can be detected by sending out data. It is important to note that the act of receiving data is completely passive in TCP; a socket that only reads cannot detect a dropped connection.

You will need to configure your communication protocol to detect a dropped connection. So, all you need to do is to try reading at some interval, and if the read fails, the connection has dropped.

@Rapsssito Rapsssito added the good first issue Good for newcomers label Feb 27, 2020
@Rapsssito Rapsssito changed the title onClose event doesn't fire when one device lose WiFi onClose event does not fire on connection lost Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants