Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- open System.Net
- open System.Text
- module http =
- let createServer (handler:(HttpListenerRequest -> HttpListenerResponse -> Async<unit>)) =
- let listener = new HttpListener()
- listener.Prefixes.Add "http://*:5000/"
- listener.Start()
- let task = Async.FromBeginEnd(listener.BeginGetContext, listener.EndGetContext)
- async {
- while true do
- let! context = task
- Async.Start(handler context.Request context.Response)
- } |> Async.Start
- // --------------------------------------------------------------------
- // implementation
- // --------------------------------------------------------------------
- let server = http.createServer (fun request response -> async {
- let txt = Encoding.ASCII.GetBytes("hello")
- response.OutputStream.Write(txt, 0, txt.Length)
- response.OutputStream.Close()
- })
- printfn "Press return to exit..."
- Console.ReadLine()
- |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement