How to have suave auto select and report the real listening port
samuelventura opened this issue · 1 comments
samuelventura commented
Code below with 0 port seems to correctly launch the server.
How can I find out programmatically the TCP port the server is listening at?
open System
open System.Threading
open Suave
[<EntryPoint>]
let main argv =
let cts = new CancellationTokenSource()
let conf =
{ defaultConfig with
cancellationToken = cts.Token
bindings = [ HttpBinding.createSimple HTTP "127.0.0.1" 0 ] }
let listening, server =
startWebServerAsync conf (Successful.OK "Hello World")
printfn "Listening %O" listening
printfn "Server %O" server
Async.Start(server, cts.Token)
printfn "Make requests now"
Console.ReadKey true |> ignore
cts.Cancel()
0 // return an integer exit code
outputs
$ dotnet run
Listening Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.FSharpOption`1[Suave.Tcp+StartedData][]] n`1[Suave.Tcp+StartedData][]]
Server Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.Unit]
Make requests now
[01:18:52 INF] Smooth! Suave listener started in 75.7ms with binding 127.0.0.1:0
ademar commented
Hi Samuel, I've pushed a fix for this issue and will be releasing a new version in the following days.