diff options
Diffstat (limited to 'ConduitServer.hs')
-rw-r--r-- | ConduitServer.hs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/ConduitServer.hs b/ConduitServer.hs new file mode 100644 index 00000000..0838ce26 --- /dev/null +++ b/ConduitServer.hs | |||
@@ -0,0 +1,48 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
2 | module Main where | ||
3 | |||
4 | import Data.Conduit.Binary | ||
5 | import Data.Conduit.Network | ||
6 | import Data.Conduit | ||
7 | import qualified Data.Conduit.List as CL | ||
8 | import qualified Data.ByteString.Char8 as S | ||
9 | |||
10 | import Network.Socket (Family(..)) | ||
11 | import Data.HList | ||
12 | import ServerC | ||
13 | |||
14 | {- | ||
15 | data AppData m = AppData | ||
16 | { appSource :: Source m ByteString | ||
17 | , appSink :: Sink ByteString m () | ||
18 | , appSockAddr :: SockAddr | ||
19 | , appLocalAddr :: Maybe SockAddr | ||
20 | } | ||
21 | -} | ||
22 | |||
23 | -- handleConnection will simply output everything | ||
24 | -- it sees from the connection to the terminal | ||
25 | handleConnection :: AppData IO -> IO () | ||
26 | handleConnection appdata = do | ||
27 | sourceLbs "<stream>\n" $$ appSink appdata -- send bytestring | ||
28 | appSource appdata $$ CL.mapM_ S.putStrLn -- display inbound bytestring | ||
29 | |||
30 | mainOld = do | ||
31 | -- Listen to port 5222 and invoke handleConnection on every | ||
32 | -- inbound connection. | ||
33 | runTCPServer (serverSettings 5222 HostAny) handleConnection | ||
34 | return () | ||
35 | |||
36 | |||
37 | |||
38 | |||
39 | handleC st src snk = do | ||
40 | sourceLbs "<stream>\n" $$ snk | ||
41 | src $$ CL.mapM_ S.putStrLn | ||
42 | |||
43 | mainC = do | ||
44 | doServer (AF_INET .*. 5222 .*. HNil) handleC | ||
45 | _ <- getLine | ||
46 | return () | ||
47 | |||
48 | main = mainC | ||