Simple sockets sample?
Jens Petersen
juhp@01.246.ne.jp
28 Jan 2002 15:33:18 +0900
"Dominic Cooney" <dominic@dcooney.com> writes:
> Does anybody know of a simple GHC Socket sample? I want to retrieve an
> HTTP URL, but I keep getting errors like this:
Funny I was trying to do the same this morning on the way to
work.
> A minimal program that exhibits the problem is below. I am using GHC
> 5.02 on Win XP Pro. When I enter the request via telnet, I do get a
> response.
>
> I assume I am making some terrible newbie mistake, so if anyone could
> point it out it would be appreciated.
> > main = withSocketsDo $ do {
> > connectTo host port;
> > sendTo host port "GET / HTTP/1.0\r\n\r\n";
> > response <- recvFrom host port;
> > putStrLn response
Hmmm, I was trying something more like (under Linux):
do
h <- connectTo host port
hPutStrLn h "GET / HTTP/1.0\n"
response <- hGetContents h
putStr response
Unfortunately this hangs waiting for the response.
Don't know why yet...
Jens