zeromq4-patterns-0.3.1.0: Haskell implementation of several ZeroMQ patterns.
Safe HaskellNone
LanguageHaskell2010

System.ZMQ4.Patterns.RequestReply

Synopsis

Type class

class (Binary a, Binary b) => RequestReply a b | a -> b Source #

A request-reply type class.

a is the request type, b is the response type.

Example:

>>> {-# LANGUAGE DataKinds #-}
>>> {-# LANGUAGE TypeApplications #-}
>>> 
>>> import Control.Concurrent.Async
>>> import Data.Binary
>>> 
>>> data A = A deriving (Binary, Show)
>>> data B = B deriving (Binary, Show)
>>> 
>>> instance RequestReply A B
>>> 
>>> reply :: A -> IO B
>>> reply _ = return B
>>> 
>>> main :: IO ()
>>> main = withAsync (responder "tcp://*:5000" reply) $ \_ ->
>>> requester "tcp://127.0.0.1:5000" A >>= print

Server and client

responder Source #

Arguments

:: RequestReply a b 
=> String

Address to bind to

-> (a -> IO b)

Reply function

-> IO () 

Start responding using the given type class.

See RequestReply for an example.

Silently ignores a request when decoding fails

request Source #

Arguments

:: RequestReply a b 
=> String

Address of the REP socket

-> a

The request

-> IO b

The reply

Request a reply.

See RequestReply for an example.

Throws an error when the response cannot be decoded.