File: socket004.hs

package info (click to toggle)
ghc-cvs 20040725-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 68,484 kB
  • ctags: 19,658
  • sloc: haskell: 251,945; ansic: 109,709; asm: 24,961; sh: 12,825; perl: 5,786; makefile: 5,334; xml: 3,884; python: 682; yacc: 650; lisp: 477; cpp: 337; ml: 76; fortran: 24; csh: 18
file content (38 lines) | stat: -rw-r--r-- 813 bytes parent folder | download | duplicates (2)
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