+++ /dev/null
-{- server
-
-The purpose of this test driver is to test TCP Stream sockets.
-All values have been hard coded since the BSD library is not used to
-query the databases for the values. In therory this code is thus not
-portable but net007/Main.hs provides a portable version using the BSD
-module.
-
-This creates a stream socket bound to port 5000 and waits for incoming
-messages it then reads all available data before closing the
-connection to that peer.
-
-No form of error checking is provided other than that already provided
-by module SocketPrim.
-
-
-TESTS:
- socket
- bindSocket
- listen
- accept
- readSocket
- sClose
-
--}
-
-
-module Main where
-
-import SocketPrim
-
-
-main =
- socket AF_INET Stream 6 >>= \ s ->
- bindSocket s (SockAddrInet 5000 iNADDR_ANY) >>
- listen s 5 >>
-
- let
- loop =
- accept s >>= \ (s',peerAddr) ->
- putStr "*** Start of Transfer ***\n" >>
- let
- read_all =
- readSocket s' 4 >>= \ (str, nbytes) ->
- if nbytes /= 0 then
- putStr str >>
- read_all
- else
- putStr "\n*** End of Transfer ***\n" >>
- sClose s'
- in
- read_all
- in
- loop
-
+++ /dev/null
-{- client
-
-Client side to net001/Main.hs.
-
-Note that the machine IP numbers have been hard coded into this
-program so it is unlikely that you will be able to run this test if
-you are not at dcs.gla.ac.uk :-(
-
-The reason for this is to aviod using the BSD module at this stage of
-testing.
-
-
-TESTS:
- socket
- connect
- writeSocket
- shutdown
- inet_addr
--}
-
-
-module Main where
-
-import SocketPrim
-
-
-starbuck = "130.209.240.81" -- SunOS 4.1.3 1 sun4c
-marcus = "130.209.247.2" -- SunOS 4.1.3 6 sun4m
-avon = "130.209.247.4" -- OSF1 V2.0 240 alpha
-karkar = "130.209.247.3" -- OSF1 V2.0 240 alpha
-
-message = "Hello World"
-
-
-main =
- socket AF_INET Stream 6 >>= \ s ->
- connect s (SockAddrInet 5000 (inet_addr avon)) >>
-
- writeSocket s message >>
- shutdown s ShutdownBoth >>
- sClose s
-
+++ /dev/null
-{- server
-
-As for net001 but gets the system to allocate the next free port
-number. It also prints out the IP number of the peer.
-
-TESTS:
- getSocketName
- inet_ntoa
-
--}
-
-module Main where
-
-import SocketPrim
-
-
-main =
- socket AF_INET Stream 6 >>= \ s ->
- bindSocket s (SockAddrInet aNY_PORT iNADDR_ANY) >>
- getSocketName s >>= \ (SockAddrInet port _) ->
- putStr ("Allocated Port Number: " ++ show port ++ "\n") >>
- listen s 5 >>
-
-
- let
- loop =
- accept s >>= \ (s',(SockAddrInet _ haddr)) ->
- putStr ("*** Start of Transfer from: " ++
- (inet_ntoa haddr) ++ "***\n") >>
- let
- read_all =
- readSocket s' 4 >>= \ (str, nbytes) ->
- if nbytes /= 0 then
- putStr str >>
- read_all
- else
- putStr "\n*** End of Transfer ***\n" >>
- sClose s'
- in
- read_all
- in
- loop
-
+++ /dev/null
-{- 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"
-
-
-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 ShutdownBoth >>
- sClose s
-
+++ /dev/null
-{- server
-
-Server as net001 but for Unix Domain Datagram sockets.
-
-TESTS:
- socket
- bindSocket
- readSocket
-
--}
-
-
-module Main where
-
-import SocketPrim
-
-
-main =
- socket AF_UNIX Datagram 0 >>= \ s ->
- bindSocket s (SockAddrUnix "sock") >>
-
- let
- loop =
- putStr "*** Start of Transfer ***\n" >>
- let
- read_all =
- readSocket s 1024 >>= \ (str, nbytes) ->
- if nbytes /= 0 then
- putStr str >>
- read_all
- else
- putStr "\n*** End of Transfer ***\n"
- in
- read_all
- in
- loop
-
+++ /dev/null
-{- client
-
-Client side of net005
-
-TESTS:
- socket
- connect
- writeSocket
- shutdown
- sClose
--}
-
-
-module Main where
-
-import SocketPrim
-
-message = "Hello World"
-
-
-main =
- socket AF_UNIX Datagram 0 >>= \ s ->
- connect s (SockAddrUnix "sock") >>
-
- writeSocket s message >>
- shutdown s ShutdownBoth >>
- sClose s
+++ /dev/null
-{- server
-
-As net003 but uses the BSD module for portability. Also prints the
-common name of the host rather than its IP number.
-
-TESTS:
- getProtocolNumber
- getSocketName
- getHostByAddr
-
--}
-
-module Main where
-
-import BSD
-import SocketPrim
-
-main =
- getProtocolNumber "tcp" >>= \ proto ->
- socket AF_INET Stream proto >>= \ s ->
- bindSocket s (SockAddrInet aNY_PORT iNADDR_ANY) >>
- getSocketName s >>= \ (SockAddrInet port _) ->
- putStr ("Allocated Port Number: " ++ show port ++ "\n") >>
- listen s 5 >>
-
-
- let
- loop =
- accept s >>= \ (s',(SockAddrInet _ haddr)) ->
- getHostByAddr AF_INET haddr >>= \ (HostEntry hname _ _ _) ->
- putStr ("*** Start of Transfer from: " ++ hname ++ "***\n") >>
- let
- read_all =
- readSocket s' 4 >>= \ (str, nbytes) ->
- if nbytes /= 0 then
- putStr str >>
- read_all
- else
- putStr "\n*** End of Transfer ***\n" >>
- sClose s'
- in
- read_all
- in
- loop
+++ /dev/null
-module Main where
-
-import SocketPrim
-import BSD
-import System
-
-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 ShutdownBoth >>
- sClose s
-
+++ /dev/null
--- Sigbjorn and I don't understand what this test is meant to do
--- It simply hangs on stdin!
-
-import IO -- 1.3
-
-import System(getArgs)
-
-main = getArgs >>= \ [user,host] ->
- let username = (user ++ "@" ++ host) in
- openFile username ReadWriteMode >>= \ cd ->
- hSetBuffering stdin NoBuffering >>
- hSetBuffering stdout NoBuffering >>
- hSetBuffering cd NoBuffering >>
- hPutStr cd speakString >>
- speak cd
-
-speakString = "Someone wants to speak with you\n"
-
-speak cd =
- (hReady cd >>= \ ready ->
- if ready then (hGetChar cd >>= putChar)
- else return () >>
-
- hReady stdin >>= \ ready ->
- if ready then (getChar >>= hPutChar cd)
- else return ()) >>
-
- speak cd