Find the port bound by the snap server

Using the httpServe -server snap-server httpServe , I can setPort 0 to instruct the server to connect to the next free port. Unfortunately, as soon as I started the http server, I cannot find a way to determine which port it is really running on. For example, my first attempt began with port 2679 - is there a way to determine this number?

+4
source share
2 answers

I wrote this patch , included in snap-server 0.9 and above, using which you can write:

 let hook dat = print $ socketPort $ head $ getStartupSockets dat let config = setStartupHook hook $ setPort 0 mempty httpServer config ... 

Now the hook will be called after the server is ready, and will print the port on which it was launched.

+3
source

The Config structure contains a bunch of getters , no?

 getPort :: Config ma -> Maybe Int 

Returns the listening port (for http)

0
source

Source: https://habr.com/ru/post/1413922/


All Articles