Skip to content

Instantly share code, notes, and snippets.

@astro
Last active December 16, 2015 12:28
Show Gist options
  • Save astro/5434482 to your computer and use it in GitHub Desktop.
Save astro/5434482 to your computer and use it in GitHub Desktop.
Winning the 0MQ book at #RealtimeConfEu
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad
import System.IO
import System.ZMQ3.Monadic
import qualified Data.ByteString.Char8 as CS
import Control.Concurrent (forkIO)
main :: IO ()
main = do
void $ forkIO $ runZMQ listener
runZMQ input
listener =
do sub <- socket Sub
subscribe sub ""
forM_ [1..254::Int] $ \i ->
connect sub $ "tcp://192.168.69." ++ show i ++ ":9000"
forever $
do receive sub >>= liftIO . CS.putStrLn
liftIO $ hFlush stdout
input =
do pub <- socket Pub
bind pub "tcp://*:9000"
forever $
liftIO CS.getLine >>= send pub [] . ("astro: " `CS.append`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment