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

Suggestion: TCP keepalive Support #91

Closed
miao2y opened this issue Jul 25, 2023 · 2 comments
Closed

Suggestion: TCP keepalive Support #91

miao2y opened this issue Jul 25, 2023 · 2 comments

Comments

@miao2y
Copy link

miao2y commented Jul 25, 2023

Hi, I'm trying to open up a VNC port on my mac so I can remotely access my computer anytime. But I found that if there is no data communication for a long time, the connection will be disconnected after a change in the middle of the network link (the client mistakenly believes that it is now connected).

Enabling TCP Keepalive can be used to prevent this from happening. Is it possible to add the option of whether to enable tcp keepalive in the parameter?

@ekzhang
Copy link
Owner

ekzhang commented Jul 25, 2023

Thanks for the suggestion! I don't think we'll add a setting to enable configuring TCP keepalive to bore, since it's intended to be minimal as an example of how to do something like this. But configuring it yourself is easy if you want to modify bore or write your own proxy based on it. You can lower it from the 2 hour default with:

use socket2::{SockRef, TcpKeepalive};

// ...

impl Server {
    // ...

    /// Start the server, listening for new connections.
    pub async fn listen(self) -> Result<()> {
        let this = Arc::new(self);
        let addr = SocketAddr::from(([0, 0, 0, 0], CONTROL_PORT));
        let listener = TcpListener::bind(&addr).await?;

        let ka = TcpKeepalive::new().with_time(Duration::from_secs(30)); // <- new line
        SockRef::from(&listener).set_tcp_keepalive(&ka)?; // <- new line
// ...

@miao2y
Copy link
Author

miao2y commented Sep 6, 2023

Eventually I added keepalive to client side and it can reconnect to server automatically. Thanks!
Solution: add: TcpKeepalive Support

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