Advertisement
Guest User

Untitled

a guest
Oct 8th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.02 KB | None | 0 0
  1. open System
  2. open System.Net
  3. open System.Text
  4.  
  5. module http =
  6.  
  7.     let createServer (handler:(HttpListenerRequest -> HttpListenerResponse -> Async<unit>)) =
  8.    
  9.         let listener = new HttpListener()
  10.  
  11.         listener.Prefixes.Add "http://*:5000/"
  12.    
  13.         listener.Start()
  14.  
  15.         let task = Async.FromBeginEnd(listener.BeginGetContext, listener.EndGetContext)
  16.    
  17.         async {
  18.  
  19.             while true do
  20.  
  21.                 let! context = task
  22.  
  23.                 Async.Start(handler context.Request context.Response)
  24.  
  25.         } |> Async.Start
  26.  
  27. // --------------------------------------------------------------------
  28. // implementation
  29. // --------------------------------------------------------------------
  30. let server = http.createServer (fun request response -> async {
  31.  
  32.         let txt = Encoding.ASCII.GetBytes("hello")
  33.  
  34.         response.OutputStream.Write(txt, 0, txt.Length)
  35.  
  36.         response.OutputStream.Close()
  37.     })
  38.  
  39. printfn "Press return to exit..."
  40.  
  41. Console.ReadLine()
  42.  
  43.     |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement