[Haskell-cafe] Re: Trying to write a TCP proxy

John Ky newhoggy at gmail.com
Wed Sep 20 09:19:11 EDT 2006


Actually, it blocks on:

>    putStrLn contents

It even blocks if I replace it with:

>    print $ length contents

Is there some kind of magic happening here?

-John

On 9/20/06, John Ky <newhoggy at gmail.com> wrote:
> 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