Skip to content
Browse files

Migrate chat example to ByteString.

  • Loading branch information...
1 parent f65cca6 commit 50ce3e197f880572a9179a33a95e93d59ab41cb5 Toralf Wittner committed Jan 22, 2010
Showing with 9 additions and 4 deletions.
  1. +2 −1 test/display.hs
  2. +7 −3 test/prompt.hs
View
3 test/display.hs
@@ -3,6 +3,7 @@ import System.IO
import System.Exit
import System.Environment
import qualified System.ZMQ as ZMQ
+import qualified Data.ByteString as SB
main :: IO ()
main = do
@@ -17,6 +18,6 @@ main = do
ZMQ.connect s addr
forever $ do
line <- ZMQ.receive s []
- putStrLn line
+ SB.putStrLn line
hFlush stdout
View
10 test/prompt.hs
@@ -1,8 +1,12 @@
+{-# LANGUAGE OverloadedStrings #-}
+import Control.Applicative
import Control.Monad
import System.IO
import System.Exit
import System.Environment
import qualified System.ZMQ as ZMQ
+import qualified Data.ByteString.UTF8 as SB
+import qualified Data.ByteString.Char8 as SB
main :: IO ()
main = do
@@ -11,11 +15,11 @@ main = do
hPutStrLn stderr "usage: prompt <address> <username>"
exitFailure
let addr = args !! 0
- name = args !! 1
+ name = SB.append (SB.fromString $ args !! 1) ": "
c <- ZMQ.init 1 1 False
s <- ZMQ.socket c ZMQ.Pub
ZMQ.connect s addr
forever $ do
- line <- getLine
- ZMQ.send s (name ++ ": " ++ line) []
+ line <- SB.fromString <$> getLine
+ ZMQ.send s (SB.append name line) []

0 comments on commit 50ce3e1

Please sign in to comment.
Something went wrong with that request. Please try again.