Created
February 4, 2011 23:08
-
-
Save softmechanics/811978 to your computer and use it in GitHub Desktop.
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
import Control.Concurrent | |
import Control.Exception | |
import Control.Monad | |
import Network.Socket | |
main = forever $ do | |
pair <- try $ socketPair AF_UNIX Stream defaultProtocol | |
case pair of | |
Left e -> do | |
let _ = e :: SomeException | |
putStrLn "sleep" | |
Right (sClient, sServer) -> do | |
putStrLn "open" | |
forkIO $ client sClient | |
forkIO $ server sServer | |
forkIO $ killer sServer sClient | |
return () | |
bufLen = 5 | |
buf = "hello" | |
client sock = forever $ do | |
send sock buf | |
_ <- recv sock bufLen | |
return () | |
server sock = forever $ do | |
buf <- recv sock bufLen | |
send sock buf | |
killer s1 s2 = do | |
putStrLn "close" | |
sClose s1 | |
sClose s2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment