/examples/Haskell/rrclient.hs

http://github.com/imatix/zguide · Haskell · 26 lines · 14 code · 4 blank · 8 comment · 0 complexity · 8ff69e2dc6ff8bc95b0b935cad0b2341 MD5 · raw file

  1. {-# LANGUAGE OverloadedStrings #-}
  2. -- |
  3. -- Request/Reply Hello World with broker (p.50)
  4. -- Binds REQ socket to tcp://localhost:5559
  5. -- Sends "Hello" to server, expects "World" back
  6. --
  7. -- Use with `rrbroker.hs` and `rrworker.hs`
  8. -- You need to start the broker first !
  9. module Main where
  10. import System.ZMQ4.Monadic
  11. import Control.Monad (forM_)
  12. import Data.ByteString.Char8 (unpack)
  13. import Text.Printf
  14. main :: IO ()
  15. main =
  16. runZMQ $ do
  17. requester <- socket Req
  18. connect requester "tcp://localhost:5559"
  19. forM_ [1..10] $ \i -> do
  20. send requester [] "Hello"
  21. msg <- receive requester
  22. liftIO $ printf "Received reply %d %s\n" (i ::Int) (unpack msg)