Cookbook/Network programming

From HaskellWiki
< Cookbook
Revision as of 10:35, 23 April 2009 by Lenny222 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The following example makes use of the Network and System.IO libraries to open a socket connection to Google and retrieve the Google home page.

    import Network;
    import System.IO;
	
    main = withSocketsDo $ do
	h <- connectTo "www.google.com" (PortNumber 80)
	hSetBuffering h LineBuffering
	hPutStr h "GET / HTTP/1.1\nhost: www.google.com\n\n"
	contents <- hGetContents h
	putStrLn contents
	hClose h