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

The statement "this.stream.setKeepAlive" did not take effect. #2042

Closed
Kino-Zh opened this issue Jun 6, 2023 · 2 comments
Closed

The statement "this.stream.setKeepAlive" did not take effect. #2042

Kino-Zh opened this issue Jun 6, 2023 · 2 comments

Comments

@Kino-Zh
Copy link

Kino-Zh commented Jun 6, 2023

If there is a possibility that this.stream.setKeepAlive is executed before the successful creation of the connection, and in that case, it becomes ineffective, you can modify your code to ensure that this.stream.setKeepAlive is called only after the connection is established.

You can move the this.stream.setKeepAlive statement inside the callback function of net.connect, ensuring that it is executed after the connection is successfully established. This way, you can ensure that the setting takes effect at the right time.

Here's an example of how you can modify your code:
const net = require('net');

const socket = net.connect(port, host, () => {
// Connection is successfully established
socket.setKeepAlive(true);
// Rest of your code
});

socket.on('error', (err) => {
// Handle connection errors
});

socket.on('close', () => {
// Handle connection closure
});

@sidorares
Copy link
Owner

#2043

@sidorares
Copy link
Owner

This should be fixed by #2043

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

2 participants