In nodejs I can detect close event for a socket but not in Rust

โš“ Rust    ๐Ÿ“… 2025-08-01    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 10      

surdeus

Warning

This post was published 124 days ago. The information described in this article may have changed.

Hi folks. Iโ€™m struggling a strange problem. I can detect the close event in nodejs for a TCP socket connection but I canโ€™t do same thing in Rust (Tokio). For example:

// Javascript
let connection = new net.Socket();
connection.on("end", (data) => {
  console.log("Connection finished.")
})

For example I can connect to this connection with CURL and when connection finishes the end function invokes. But I canโ€™t do same thing in tokio::net::TcpStream

Yes I know that we canโ€™t really understand that is the connection live. All network connections actaully isnโ€™t exist but at least I want to detect the FIN flag sent from the peer. How can I do this?

7 posts - 4 participants

Read full topic

๐Ÿท๏ธ Rust_feed