Created
December 9, 2016 03:41
-
-
Save jeremyjh/416f50f33a6c65511672b53013392239 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Main where | |
import Control.Distributed.Process hiding (call) | |
import Control.Distributed.Process.Node as Node (initRemoteTable, runProcess, newLocalNode) | |
import Control.Distributed.Process.Extras (resolve, __remoteTable) | |
import Network.Transport.TCP | |
import Control.Concurrent (threadDelay) | |
import Control.Monad | |
import Network.Transport hiding (send) | |
import System.Environment | |
import Data.ByteString.Char8 as BS | |
main :: IO () | |
main = do | |
args <- getArgs | |
case args of | |
["server", host, port] -> | |
startServer host port | |
["client", host, port, serv] -> | |
startClient host port serv | |
where | |
startServer h p | |
= do startCommon h p $ do | |
register "foo" =<< getSelfPid | |
forever $ liftIO $ threadDelay 10000 | |
startClient h p srv | |
= do startCommon h p $ do | |
let n = makeNodeId srv | |
liftIO $ print n | |
Just s <- resolve (n, "foo") | |
liftIO $ print s | |
send s () | |
startCommon h p k | |
= do Right tcp <- createTransport h p defaultTCPParameters | |
n <- newLocalNode tcp (__remoteTable initRemoteTable ) | |
Node.runProcess n k | |
makeNodeId :: String -> NodeId | |
makeNodeId addr = NodeId . EndPointAddress . BS.concat $ [BS.pack addr, BS.pack ":0"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment