Skip to content

Instantly share code, notes, and snippets.

@devhawk
Created August 28, 2009 19:55
Show Gist options
  • Save devhawk/177186 to your computer and use it in GitHub Desktop.
Save devhawk/177186 to your computer and use it in GitHub Desktop.
open System.IO
open System.Net
open System.Net.Sockets
open Microsoft.FSharp.Control
open Extensions
let rec relay_loop (http:HttpListener) (socket:Socket) =
async {
// Async.Any (http.AsyncGetContext(), socket.AsyncReceive())
return! relay_loop http socket
}
let setup (socket:Socket) =
async {
//todo: read URL from client
let url = System.Guid.NewGuid().ToString("N")
use http = new HttpListener()
do http.Prefixes.Add(url)
do http.Start()
Async.Start(relay_loop http socket) }
let rec listen (listener:TcpListener) =
async {
let! socket = listener.AsyncAcceptSocket()
do Async.Start(setup socket)
return! listen listener
}
let tl = new TcpListener(IPAddress.Any, 6694)
tl.Start()
Async.Start (listen tl)
printfn "press return to exit"
System.Console.ReadLine() |> ignore
tl.Stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment