So, I was barely able to install libzmq on the Windows desktop, and then zeromq-haskell with cabal. I wanted to test api by associating a python program with a haskell program in an application like hello-world.
Thus, the simplest template that I see is a request-response template. At first I tried to make a server in haskell (REP) and a client in python (REQ), the witch failed, no matter what. The generated exception message was Exception: receive: failed (No error).
So, I look at the source code of System.ZMQ and System.ZMQ.Base, and I see that receiving causes an error when calling c_zmq_recv, because in turn the maps are mapped directly to calling ffi (?) On the C api. So I think that maybe I didn’t do the installation properly, but then I try to make the client in Haskell and the server in python, and I notice that it works without any problems, so maybe the recv interface is not a problem here.
Here is the haskell code below, with client and server functions
import System.ZMQ import Control.Monad (forM_,forever) import Data.ByteString.Char8 (pack,unpack) import Control.Concurrent (threadDelay) clientMain :: IO () clientMain = withContext 1 (\context->do putStrLn "Connecting to server" withSocket context Req $ (\socket-> do connect socket "tcp://127.0.0.1:5554" putStrLn $ unwords ["Sending request"] send socket (pack "Hello...") [] threadDelay (1*1000*1000) reply<-receive socket [] putStrLn $ unwords ["Received response : ",unpack reply])) serverMain :: IO () serverMain = withContext 1 (\context-> do putStrLn "Listening at 5554" withSocket context Rep $ (\socket-> do connect socket "tcp://127.0.0.1:5554" forever $ do message<-receive socket [] -- this throws an IO Exception putStrLn $ unwords ["Received request : ",unpack message] threadDelay (1*1000*1000) send socket (pack "World") [] )) main :: IO () main = serverMain -- replace with clientMain and it works
Now I really couldn’t check all the other communication methods (push / pull, subscribe / publish, pair, etc.), and for what I need the python server / haskell client, it’s probably better, but I'm curious about the weather, I do what something is wrong, or if any part of my code is broken in any way.
Thanks in advance