Skip to content

Instantly share code, notes, and snippets.

@softmechanics
Created February 4, 2011 23:08
Show Gist options
  • Save softmechanics/811978 to your computer and use it in GitHub Desktop.
Save softmechanics/811978 to your computer and use it in GitHub Desktop.
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