[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / misc / examples / net008 / Main.hs
diff --git a/ghc/misc/examples/net008/Main.hs b/ghc/misc/examples/net008/Main.hs
new file mode 100644 (file)
index 0000000..8c33929
--- /dev/null
@@ -0,0 +1,22 @@
+module Main where
+
+import SocketPrim
+import BSD
+import LibSystem
+
+
+main =
+    getArgs                                    >>= \ [host, port, message] ->
+    getProtocolNumber "tcp"                    >>= \ proto ->
+    socket AF_INET Stream proto                        >>= \ s ->
+    getHostByName host                         >>= \ (HostEntry _ _ _ haddrs) ->
+    connect s (SockAddrInet (read port) 
+               (head haddrs))                  >>
+
+    getPeerName s                              >>= \ (SockAddrInet _ haddr) ->  
+    getHostByAddr AF_INET haddr                        >>= \ (HostEntry hname _ _ _) ->
+    putStr ("Connected to : " ++ hname ++ "\n") >>
+    writeSocket s message                      >>
+    shutdown s 2                               >>
+    sClose s
+