[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / misc / examples / net004 / Main.hs
diff --git a/ghc/misc/examples/net004/Main.hs b/ghc/misc/examples/net004/Main.hs
new file mode 100644 (file)
index 0000000..3948707
--- /dev/null
@@ -0,0 +1,33 @@
+{- 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 where
+
+import SocketPrim
+import LibSystem
+
+
+starbuck    = "130.209.240.81"
+marcus     = "130.209.247.2"
+
+
+main =
+    getArgs                                    >>= \ [port, message] ->
+    socket AF_INET Stream 6                    >>= \ s ->
+    connect s (SockAddrInet (read port) (inet_addr starbuck))  >>
+
+    getPeerName s                      >>= \ (SockAddrInet p haddr) ->   
+    putStr ("Connected to : " ++ (inet_ntoa haddr) ++ "\n") >>
+    writeSocket s message                      >>
+    shutdown s 2                               >>
+    sClose s
+