binary-protocol-1.0: Monad to ease implementing a binary network protocol.




Monad to ease writing a binary network protocol.



runProtocol :: BinaryProtocol a -> Handle -> Handle -> IO aSource

Take a BinaryProtocol monad and run it on the given handles for respectively reading and writing. (The two given handles are allowed to be the same if the same handle is used for reading and writing.)

Note: We run L.hGetContents on the read handle, so don't expect to be able to use it after you have called this function.

receive :: Binary a => BinaryProtocol aSource

Read in a value of type a from the connection; a must be an instance of the Binary class.

send :: Binary a => a -> BinaryProtocol ()Source

Send a value of type a down the connection; a must be an instance of the Binary class.

flush :: BinaryProtocol ()Source

Flush buffered send data down the connection.

Note: You need to make sure to call this between sending requests and receiving responses in order to ensure that the request has actually been sent down the connection; otherwise you might get stuck waiting for a response that will not come.