Created
August 28, 2009 19:55
-
-
Save devhawk/177186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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