Last active
December 16, 2015 12:28
-
-
Save astro/5434482 to your computer and use it in GitHub Desktop.
Winning the 0MQ book at #RealtimeConfEu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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