summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib/socket/socket004.hs
blob: d7fbdc91bcd41ef128a1ba8c7e50046f770d7015 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{- client

As for net002 but reads port number and message as arguments.
It also prints out the IP number of the peer machine.



TESTS:
    getPeerName
-}


module Main(main) where

import SocketPrim
import System


starbuck    = "130.209.240.81"
marcus	    = "130.209.247.2"

nauru	    = "130.209.247.5"		-- Linux 2.0.30 (RH-4.2) x86
easter	    = "130.209.247.6"		-- Linux 2.0.30 (RH-4.2) x86


main =
    getArgs					>>= \ [port, message] ->
    socket AF_INET Stream 6			>>= \ s ->
    inet_addr easter				>>= \ i_addr ->
    connect s (SockAddrInet (mkPortNumber (read port)) i_addr)	>>

    getPeerName s			>>= \ (SockAddrInet p haddr) ->   
    inet_ntoa haddr		        >>= \ a ->
    putStr ("Connected to : " ++ a ++ "\n") >>
    writeSocket s message			>>
    shutdown s ShutdownBoth			>>
    sClose s