d7fbdc91bcd41ef128a1ba8c7e50046f770d7015
[ghc-hetmet.git] / ghc / tests / lib / socket / socket004.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(main) where
14
15 import SocketPrim
16 import System
17
18
19 starbuck    = "130.209.240.81"
20 marcus      = "130.209.247.2"
21
22 nauru       = "130.209.247.5"           -- Linux 2.0.30 (RH-4.2) x86
23 easter      = "130.209.247.6"           -- Linux 2.0.30 (RH-4.2) x86
24
25
26 main =
27     getArgs                                     >>= \ [port, message] ->
28     socket AF_INET Stream 6                     >>= \ s ->
29     inet_addr easter                            >>= \ i_addr ->
30     connect s (SockAddrInet (mkPortNumber (read port)) i_addr)  >>
31
32     getPeerName s                       >>= \ (SockAddrInet p haddr) ->   
33     inet_ntoa haddr                     >>= \ a ->
34     putStr ("Connected to : " ++ a ++ "\n") >>
35     writeSocket s message                       >>
36     shutdown s ShutdownBoth                     >>
37     sClose s
38