Closed sbarcelona11 closed 2 years ago
@sbarcelona11, thanks for the PR! However, I believe the timeout is already being handled by the JS code. This might cause duplicated events or incorrect timing of them.
@sbarcelona11, thanks for the PR! However, I believe the timeout is already being handled by the JS code. This might cause duplicated events or incorrect timing of them.
Can you provide me with an example of timeout on JS, please?
Please take a look on https://docs.oracle.com/javase/8/docs/api/java/net/ServerSocket.html#setSoTimeout-int- to understand the changes made on your code
Right now, when the socket is being connected this code is executed:
// Timeout
if (customOptions.timeout) this.setTimeout(customOptions.timeout);
else if (this._timeout) this._activateTimer();
This timeout will generate a 'timeout'
event once the timeout is depleted, emulating node's net API.
Right now, when the socket is being connected this code is executed:
// Timeout if (customOptions.timeout) this.setTimeout(customOptions.timeout); else if (this._timeout) this._activateTimer();
This timeout will generate a
'timeout'
event once the timeout is depleted, emulating node's net API.
This is for the socket. My changes are for the server. You don´t have a timeout for the TcpSocketServer. The server lives infinity and If I have an error on my app, then I can´t create the TcpSocketServer again.
@sbarcelona11, the purpose of this library is to mimic node's net API. That's why I cannot accept your PR, I am sure it will make it easier for your current setup but I would like to reduce the API to the bare minimum. My apologies.
You could look for examples of implementations in node for your problem and they will probably work with react-native-tcp-socket
.
I have some errors on the "Host not reachable error handling". I implement a way to release the connection overriding the timeout for the SO. This PR adds a new parameter called timeout and can you use it to use a custom timeout.