diff options
author | Camil Staps | 2016-03-19 22:39:11 +0100 |
---|---|---|
committer | Camil Staps | 2016-03-19 22:39:11 +0100 |
commit | f6e857c1f4c6ac34760755508ed861a29b51d791 (patch) | |
tree | 6126e9bf3509699e9b84e25a2796b2b0b8824045 | |
parent | restricted existentially qualified type (diff) |
TCPIP
-rw-r--r-- | tcpip/test_client.icl | 20 | ||||
-rw-r--r-- | tcpip/test_server.icl | 28 |
2 files changed, 48 insertions, 0 deletions
diff --git a/tcpip/test_client.icl b/tcpip/test_client.icl new file mode 100644 index 0000000..99a0a74 --- /dev/null +++ b/tcpip/test_client.icl @@ -0,0 +1,20 @@ +module test_client + +import StdEnv +import StdMaybe +import TCPIP + +clientConnect :: !*World -> (!TCP_DuplexChannel, !*World) +clientConnect w +# (mbIPAddr, w) = lookupIPAddress "localhost" w +| isNothing mbIPAddr = abort "DNS lookup failed\n" +# ipAddr = fromJust mbIPAddr +# (tReport, mbDuplex, w) = connectTCP_MT Nothing (ipAddr, 12345) w +| tReport <> TR_Success = abort "Can't connect to port 12345\n" +# duplexChannel = fromJust mbDuplex +# (sChannel, w) = send (toByteSeq "Hello world!\n") duplexChannel.sChannel w + duplexChannel = {duplexChannel & sChannel=sChannel} += (duplexChannel, w) + +Start w = clientConnect w + diff --git a/tcpip/test_server.icl b/tcpip/test_server.icl new file mode 100644 index 0000000..c5cf11f --- /dev/null +++ b/tcpip/test_server.icl @@ -0,0 +1,28 @@ +module test_server + +import StdEnv +import StdLib +import TCPIP + +Start w +# (ok, mbListener, w) = openTCP_Listener 12345 w +| not ok = abort "Couldn't open port 12345\n" +# listener = fromJust mbListener +# (listener, w) = loop listener w //((_,duplexChannel),listener,w) = receive listener w +# w = closeRChannel listener w += w +where + loop :: !TCP_Listener !*World -> (TCP_Listener, *World) + loop li w + # ((ip,dupChan),li,w) = receive li w + # (msg, rChan, w) = receive dupChan.rChannel w + dupChan = {dupChan & rChannel=rChan} + # (sChan, w) = send msg dupChan.sChannel w + dupChan = {dupChan & sChannel=sChan} + # w = closeRChannel dupChan.rChannel w + # w = closeChannel dupChan.sChannel w + # (io, w) = stdio w + # io = fwrites (toString ip +++ ": " +++ toString msg) io + # (_, w) = fclose io w + | length [1..999999999] == 999999999 = loop li w + |