为什么TcpClient.Connected()被TcpListener关闭后显示为true? F#

Why does TcpClient.Connected() show true after being closed by TcpListener? F#

所以我试图通过 F# 了解有关 TCP 的更多信息,当我在 1 秒后从侦听器端关闭连接时,它仍然显示客户端已连接到客户端。

服务器:

open System.Net
open System.Net.Sockets
open System.Threading

let tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 1000)

let rec listen() =
    printfn "Listening..."

    let tcpClient = tcpListener.AcceptTcpClient()
    printfn "Connected!"

    Thread.Sleep(1000)

    tcpClient.Close()
    printfn "Disconnected."

    listen()

tcpListener.Start()
listen()

客户:

open System
open System.Net.Sockets
open System.Threading

let connect() =
    let tcpClient = new TcpClient("127.0.0.1", 1000)
    printfn "Connected!"

    let rec loop() =
        Thread.Sleep(100)

        let isConnected = tcpClient.Connected

        if isConnected = false then
            printfn "Disconnected."
        else
            loop()

    Console.Read() |> ignore

connect()

您似乎从未调用 loop 函数,因此它从未实际检查连接。