diff options
author | Joe Crayne <joe@jerkface.net> | 2018-09-08 08:28:01 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-12-16 14:08:26 -0500 |
commit | 46334ab5763b41f4d13582e88e9d970e9bfa3ce8 (patch) | |
tree | 59647da2770d945e7c9443a13476a2a3efa4c4f4 /simplechat.hs | |
parent | 5f353ee3acc88e745105badf0148d22c281e4d32 (diff) |
Deleted unused modules.
Diffstat (limited to 'simplechat.hs')
-rw-r--r-- | simplechat.hs | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/simplechat.hs b/simplechat.hs deleted file mode 100644 index 84b33e13..00000000 --- a/simplechat.hs +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
2 | {-# LANGUAGE ScopedTypeVariables #-} | ||
3 | |||
4 | import Data.HList.TypeEqGeneric1() | ||
5 | import Data.HList.TypeCastGeneric1() | ||
6 | import ByteStringOperators | ||
7 | |||
8 | import Data.ByteString.Lazy.Char8 as L | ||
9 | ( ByteString | ||
10 | , hPutStrLn | ||
11 | , init ) | ||
12 | import System.IO | ||
13 | ( Handle | ||
14 | ) | ||
15 | import Control.Concurrent (forkIO) | ||
16 | import Control.Concurrent.Chan | ||
17 | import Data.HList | ||
18 | |||
19 | import Connection.Tcp | ||
20 | |||
21 | |||
22 | startCon socket st = do | ||
23 | let chan = hOccursFst st | ||
24 | nr = hOccursFst st :: ConnId | ||
25 | hdl = hOccursFst st :: Handle | ||
26 | quit = writeChan chan (nr,Nothing) | ||
27 | broadcast msg = writeChan chan (nr,Just msg) | ||
28 | chan' <- dupChan chan | ||
29 | reader <- forkIO $ fix $ \loop -> do | ||
30 | (nr', line) <- readChan chan' | ||
31 | case ( line, nr==nr') of | ||
32 | ( Nothing , True ) -> Prelude.putStrLn "quit-client." | ||
33 | ( Just msg , False ) -> hPutStrLn hdl msg >> loop | ||
34 | _ -> loop | ||
35 | |||
36 | hPutStrLn hdl "Hi, what's your name?" | ||
37 | line <- getPacket hdl | ||
38 | let name = L.init line | ||
39 | Prelude.putStrLn $ "readFst: " ++ show line | ||
40 | hPutStrLn hdl ("Welcome, " <++> name <++> "!") | ||
41 | broadcast ("--> " <++> name <++> " entered.") | ||
42 | |||
43 | return (name .*. ConnectionFinalizer quit .*. st) | ||
44 | |||
45 | doCon st bs cont = do | ||
46 | let hdl = hOccursFst st :: Handle | ||
47 | nr = hOccursFst st :: ConnId | ||
48 | chan = hOccursFst st | ||
49 | broadcast msg = writeChan chan (nr,Just msg) | ||
50 | name = hHead st | ||
51 | Prelude.putStrLn $ "read: " ++ show bs | ||
52 | case bs of | ||
53 | "quit\n" -> hPutStrLn hdl "Bye!" | ||
54 | _ -> do | ||
55 | broadcast (name <++> ": " <++> L.init bs) | ||
56 | cont () | ||
57 | |||
58 | |||
59 | main = do | ||
60 | (chan :: Chan (ConnId, Maybe ByteString)) <- newChan | ||
61 | doServer (5222 .*. chan .*. HNil) | ||
62 | doCon | ||
63 | startCon | ||
64 | getLine | ||
65 | |||
66 | |||