diff options
Diffstat (limited to 'simplechat.hs')
-rw-r--r-- | simplechat.hs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/simplechat.hs b/simplechat.hs index 54545b9b..bf592db3 100644 --- a/simplechat.hs +++ b/simplechat.hs | |||
@@ -5,7 +5,6 @@ import Data.HList.TypeEqGeneric1() | |||
5 | import Data.HList.TypeCastGeneric1() | 5 | import Data.HList.TypeCastGeneric1() |
6 | import ByteStringOperators | 6 | import ByteStringOperators |
7 | 7 | ||
8 | import Server | ||
9 | import Data.ByteString.Lazy.Char8 as L | 8 | import Data.ByteString.Lazy.Char8 as L |
10 | ( ByteString | 9 | ( ByteString |
11 | , hPutStrLn | 10 | , hPutStrLn |
@@ -17,6 +16,8 @@ import Control.Concurrent (forkIO) | |||
17 | import Control.Concurrent.Chan | 16 | import Control.Concurrent.Chan |
18 | import Data.HList | 17 | import Data.HList |
19 | 18 | ||
19 | import Server | ||
20 | |||
20 | 21 | ||
21 | startCon socket st = do | 22 | startCon socket st = do |
22 | let chan = hOccursFst st | 23 | let chan = hOccursFst st |
@@ -42,17 +43,17 @@ startCon socket st = do | |||
42 | return (name .*. ConnectionFinalizer quit .*. st) | 43 | return (name .*. ConnectionFinalizer quit .*. st) |
43 | 44 | ||
44 | doCon st bs cont = do | 45 | doCon st bs cont = do |
45 | let hdl = hOccursFst st :: Handle | 46 | let hdl = hOccursFst st :: Handle |
46 | nr = hOccursFst st :: ConnId | 47 | nr = hOccursFst st :: ConnId |
47 | chan = hOccursFst st | 48 | chan = hOccursFst st |
48 | broadcast msg = writeChan chan (nr,Just msg) | 49 | broadcast msg = writeChan chan (nr,Just msg) |
49 | name = hHead st | 50 | name = hHead st |
50 | Prelude.putStrLn $ "read: " ++ show bs | 51 | Prelude.putStrLn $ "read: " ++ show bs |
51 | case bs of | 52 | case bs of |
52 | "quit\n" -> hPutStrLn hdl "Bye!" | 53 | "quit\n" -> hPutStrLn hdl "Bye!" |
53 | _ -> do | 54 | _ -> do |
54 | broadcast (name <++> ": " <++> L.init bs) | 55 | broadcast (name <++> ": " <++> L.init bs) |
55 | cont () | 56 | cont () |
56 | 57 | ||
57 | 58 | ||
58 | main = do | 59 | main = do |