Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to have suave auto select and report the real listening port #754

Closed
samuelventura opened this issue May 7, 2021 · 1 comment
Closed

Comments

@samuelventura
Copy link

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 ademar closed this as completed in 48b34bd May 11, 2021
@ademar
Copy link
Member

ademar commented May 11, 2021

Hi Samuel, I've pushed a fix for this issue and will be releasing a new version in the following days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants