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