3948707df3641b3742f0787292771352e93433d7
[ghc-hetmet.git] / ghc / misc / examples / net004 / Main.hs
1 {- client
2
3 As for net002 but reads port number and message as arguments.
4 It also prints out the IP number of the peer machine.
5
6
7
8 TESTS:
9     getPeerName
10 -}
11
12
13 module Main where
14
15 import SocketPrim
16 import LibSystem
17
18
19 starbuck    = "130.209.240.81"
20 marcus      = "130.209.247.2"
21
22
23 main =
24     getArgs                                     >>= \ [port, message] ->
25     socket AF_INET Stream 6                     >>= \ s ->
26     connect s (SockAddrInet (read port) (inet_addr starbuck))   >>
27
28     getPeerName s                       >>= \ (SockAddrInet p haddr) ->   
29     putStr ("Connected to : " ++ (inet_ntoa haddr) ++ "\n") >>
30     writeSocket s message                       >>
31     shutdown s 2                                >>
32     sClose s
33