8c339297e2cff75c33d7a38e395b2f0655375f40
[ghc-hetmet.git] / ghc / misc / examples / net008 / Main.hs
1 module Main where
2
3 import SocketPrim
4 import BSD
5 import LibSystem
6
7
8 main =
9     getArgs                                     >>= \ [host, port, message] ->
10     getProtocolNumber "tcp"                     >>= \ proto ->
11     socket AF_INET Stream proto                 >>= \ s ->
12     getHostByName host                          >>= \ (HostEntry _ _ _ haddrs) ->
13     connect s (SockAddrInet (read port) 
14                 (head haddrs))                  >>
15
16     getPeerName s                               >>= \ (SockAddrInet _ haddr) ->  
17     getHostByAddr AF_INET haddr                 >>= \ (HostEntry hname _ _ _) ->
18     putStr ("Connected to : " ++ hname ++ "\n") >>
19     writeSocket s message                       >>
20     shutdown s 2                                >>
21     sClose s
22