[Haskell-cafe] Trying to write a TCP proxy

John Ky newhoggy at gmail.com
Wed Sep 20 07:59:36 EDT 2006


Hello,

I'm trying to use haskell to put together a TCP proxy I can put
between my browser and my webserver.

This is as far as I got.  The webserver isn't returning my request:

> listen = withSocketsDo $ do
>   putStrLn "Listening..."
>   socket <- listenOn $ PortNumber 8082
>   (handleToClient, hostName, portNumber) <- accept socket
>   putStrLn "Connected to client"
>   contents <- hGetContents handleToClient
>   putStrLn "Received from client:"
>   putStrLn contents
>   handleToServer <- connectTo "127.0.0.1" (PortNumber 8080)
>   putStrLn "Connected to server"
>   hPutStrLn handleToServer contents
>   putStrLn "Waiting for server to respond"
>   hPutStrLn handleToServer "\r\n\r\n"
>   putStrLn "Waiting for server to respond"
>   result <- hGetContents handleToServer
>   putStrLn result
>   hClose handleToServer
>   hClose handleToClient
>   sClose socket

Am I doing something wrong?

Thanks,

-John


More information about the Haskell-Cafe mailing list