Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- serve :: ServeOptions -> (Socket -> IO ()) -> IO ()
- data ServeOptions
- port :: PortNumber -> ServeOptions
Serve
:: ServeOptions | |
-> (Socket -> IO ()) | What to do each time a new client connects to your server. These actions run concurrently in separate threads. |
-> IO () | Perpetually listens for incoming connections and runs
the |
Example
Suppose you have a function that reads an HTTP request from a socket and then writes an HTTP response back to the socket.
handleHttpRequest :: Socket
-> IO ()
Then you might start a server by running the following in GHCi:
λ> import SocketsAndPipes.Serve λ>serve
(port
8000) handleHttpRequest
And while the server is still running, test it on the command line like so:
$ curl http://localhost:8000
Options
data ServeOptions Source #
The first argument to serve
.
:: PortNumber | The port number that your server will listen on |
-> ServeOptions |
Alternatives
The serve
function here is somewhat narrowly tailored
to fit our purposes in Sockets and Pipes.
Some other packages have more expansive offerings: