Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jfischoff/port-utils
Utilities for creating and waiting on sockets
https://github.com/jfischoff/port-utils
haskell networking testing
Last synced: 27 days ago
JSON representation
Utilities for creating and waiting on sockets
- Host: GitHub
- URL: https://github.com/jfischoff/port-utils
- Owner: jfischoff
- License: bsd-3-clause
- Created: 2018-11-02T01:11:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-27T20:41:58.000Z (over 5 years ago)
- Last Synced: 2024-09-29T17:41:58.572Z (about 1 month ago)
- Topics: haskell, networking, testing
- Language: Haskell
- Homepage:
- Size: 47.9 KB
- Stars: 3
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# port-utils
## openFreePort
This is another version of `warp`'s `openFreePort` function. This function has fewer dependencies than the `warp` version.
`openFreePort` returns a socket on a random port and the port it has been bound to.
```haskell
openFreePort :: IO (Int, Socket)
```## wait
`wait` will attempt to connect to a host and port until it is successful. Between each unsuccessful attempt, it sleeps for 10 ms.
Here is an example of the primary function:
```haskell
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:
```bash
while ! nc -z localhost 7000 ; do sleep 0.01 ; done
```The bash script above was copied from this stackoverflow answer https://stackoverflow.com/a/50008755