zmq: test for hwm / general zmq stuff
authorMax Voit <max.voit+gtdv@with-eyes.net>
Thu, 25 Jun 2015 13:29:28 +0000 (15:29 +0200)
committerMax Voit <max.voit+gtdv@with-eyes.net>
Thu, 25 Jun 2015 13:29:28 +0000 (15:29 +0200)
zmq-concept/hwmtest.hs [new file with mode: 0644]

diff --git a/zmq-concept/hwmtest.hs b/zmq-concept/hwmtest.hs
new file mode 100644 (file)
index 0000000..6e2457c
--- /dev/null
@@ -0,0 +1,48 @@
+{-# LANGUAGE OverloadedStrings #-}
+import System.ZMQ4
+import Control.Concurrent 
+import Control.Monad
+import qualified Data.ByteString.Char8 as CS
+
+receiver = do
+    ctx <- context
+    sock <- socket ctx Dealer
+    --setReceiveHighWM (restrict (100*1000)) sock
+    connect sock "tcp://localhost:3335"
+    send sock [] "new here"
+    forever $ do 
+        msg <- receive sock
+        CS.putStrLn $ "R " `CS.append` msg
+    -- this is important since garbage collection!
+    close sock
+    term ctx
+
+main = do
+    forkIO receiver
+
+    ctx <- context
+    sock <- socket ctx Router
+    --setReceiveHighWM (restrict (100*1000)) sock
+    bind sock "tcp://*:3335"
+
+    ident <- receive sock
+    _ <- receive sock
+
+    forever $ do 
+        c <- getLine
+        case c of
+            'v':_ -> forM_ [0..100] $ \i -> do
+               send sock [SendMore] ident
+               send sock [] $ CS.pack $ show i 
+            's':_ -> forM_ [0..1000] $ \i -> do
+               send sock [SendMore] ident
+               send sock [] $ CS.pack $ show i 
+            'b':_ -> forM_ [0..1000000] $ \i -> do
+               send sock [SendMore] ident
+               send sock [] $ CS.pack $ show i 
+            _ -> print "unknown command"
+
+    -- this is important since garbage collection!
+    close sock
+    term ctx
+