Simple sockets sample?
Dominic Cooney
dominic@dcooney.com
Mon, 28 Jan 2002 13:33:42 +1000
Does anybody know of a simple GHC Socket sample? I want to retrieve an
HTTP URL, but I keep getting errors like this:
Main> main
*** Exception: failed
Action: fileSize
Reason: Bad file descriptor
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.
> module Main(main) where
> import Socket
> main :: IO ()
> main = withSocketsDo $ do {
> connectTo host port;
> sendTo host port "GET / HTTP/1.0\r\n\r\n";
> response <- recvFrom host port;
> putStrLn response
> }
> where
> host = "localhost"
> port = Service "http"
Sincerely,
Dominic Cooney