Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.