This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let udpClientListeningController = | |
Agent.Start(fun inbox -> | |
let rec loop (runningClients:UdpClient seq) = async { | |
let! msg = inbox.Receive() | |
let closeRunningClients () = runningClients |> Seq.iter (fun client -> client.ProtectedClose()) | |
match msg with | |
| ListenForSearchResponsesAndNotifyAdverts (port, ipAddresses) -> | |
closeRunningClients () | |
let uniAndMulticastUdpClients = seq { | |
let portIPPairs = ipAddresses |> Seq.zip (seq { yield port }) | |
yield! portIPPairs |> Seq.map createUnicastClient | |
yield! portIPPairs |> Seq.map (snd >> createMulticastClient) | |
} | |
//Start em up. | |
uniAndMulticastUdpClients | |
|> Seq.iter (udpClientReceiveLoopAsync >> Async.Start) | |
return! loop uniAndMulticastUdpClients | |
| StopListening -> | |
closeRunningClients () | |
return! loop Seq.empty | |
} | |
loop Seq.empty | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment