Suave is a simple web development F# library providing a lightweight web server and a set of combinators to manipulate route flow and task composition.
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
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?
outputs