@@ -15,7 +15,7 @@ counter = go 0
15 b <- expect
15 b <- expect
17 Nothing -> go (n + 1)
17 Nothing -> go (n + 1)
18− Just them -> send them n
18+ Just them -> send them n >> go 0
20count :: Int -> ProcessId -> Process ()
20count :: Int -> ProcessId -> Process ()
21count n them = do
21count n them = do
@@ -25,22 +25,19 @@ count n them = do
25 n' <- expect
25 n' <- expect
26 liftIO $ print (n == n')
26 liftIO $ print (n == n')
28+initialProcess :: String -> Process ()
29+initialProcess "SERVER" = do
31+ liftIO $ BSL.writeFile "counter.pid" (encode us)
33+initialProcess "CLIENT" = do
34+ n <- liftIO $ getLine
35+ them <- liftIO $ decode <$> BSL.readFile "counter.pid"
28main :: IO ()
38main :: IO ()
30− args <- getArgs
40+ [role, host, port] <- getArgs
32− ["server", host, port] -> do
33− Right transport <- createTransport host port defaultTCPParameters
41+ Right transport <- createTransport host port defaultTCPParameters
34− node <- newLocalNode transport initRemoteTable
37− liftIO $ BSL.writeFile "counter.pid" (encode us)
39− ["client", host, port, n] -> do
40− Right transport <- createTransport host port defaultTCPParameters
41− node <- newLocalNode transport initRemoteTable
42+ node <- newLocalNode transport initRemoteTable
42− runProcess node $ do
43+ runProcess node $ initialProcess role
43− them <- liftIO $ decode <$> BSL.readFile "counter.pid"
45− _ -> error "Invalid arguments"