File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -55,30 +55,35 @@ main :: IO ()
5555main = do
5656 serverAddr <- newEmptyMVar
5757 clientDone <- newEmptyMVar
58+ serverDone <- newEmptyMVar
5859
5960 Right transport <- createTransport "127.0.0.1" "10080" defaultTCPParameters
60-
61+
6162 -- "Server"
6263 forkIO $ do
6364 Right endpoint <- newEndPoint transport
6465 putMVar serverAddr (address endpoint)
65-
66+
6667 forever $ do
6768 event <- receive endpoint
6869 case event of
6970 Received _ msg -> print msg
71+ ConnectionClosed{} -> putMVar serverDone ()
7072 _ -> return () -- ignore
7173
74+
7275 -- "Client"
7376 forkIO $ do
7477 Right endpoint <- newEndPoint transport
75- Right conn <- do addr <- readMVar serverAddr
78+ Right conn <- do addr <- readMVar serverAddr
7679 connect endpoint addr ReliableOrdered defaultConnectHints
7780 send conn [ fromString "Hello world"]
78- putMVar clientDone ()
81+ putMVar clientDone conn
7982
8083 -- Wait for the client to finish
81- takeMVar clientDone
84+ conn <- takeMVar clientDone
85+ close conn
86+ takeMVar serverDone
8287{% endhighlight %}
8388
8489We create a "server" and a "client" (each represented by an ` EndPoint ` ).
You can’t perform that action at this time.
0 commit comments