port-utils: Utilities for creating and waiting on ports

[ bsd3, library, unclassified ] [ Propose Tags ]

Utilities for creating and waiting on ports.

openFreePort will create a socket bound to a random port (like warp's openFreePort).

wait will attempt to connect to given host and port repeatedly until successful.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.2.0.0, 0.2.1.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), network [details]
License BSD-3-Clause
Copyright 2018 Jonathan Fischoff
Author Jonathan Fischoff
Maintainer jonathangfischoff@gmail.com
Home page https://github.com/jfischoff/port-utils#readme
Bug tracker https://github.com/jfischoff/port-utils/issues
Source repo head: git clone https://github.com/jfischoff/port-utils
Uploaded by JonathanFischoff at 2018-11-02T15:48:40Z
Distributions LTSHaskell:0.2.1.0, NixOS:0.2.1.0, Stackage:0.2.1.0
Reverse Dependencies 7 direct, 6 indirect [details]
Downloads 5019 total (39 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-11-02 [all 1 reports]

Readme for port-utils-0.1.0.2

[back to package description]

port-utils

openFreePort

This is another version of warp's openFreePort function. Nice if you don't already depend on warp.

openFreePort returns a socket on random port and the port it has been bound to.

openFreePort :: IO (Int, Socket)

wait

wait will attempt to connect to a host and port until successful. Between each unsuccessful attempt it sleeps for 10 ms

Here is an example of the primary function:

import Network.Socket.Wait (wait)

void $ forkIO $ Warp.run 7000 app
-- Wait for the server to start listening on the socket
wait "127.0.0.1" 7000
-- Communicate with the server
...

In bash one could write:

while ! nc -z localhost 7000 ; do sleep 0.01 ; done

The above was copied from this stackoverflow answer https://stackoverflow.com/a/50008755