summaryrefslogtreecommitdiff
path: root/ConduitServer.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ConduitServer.hs')
-rw-r--r--ConduitServer.hs48
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 #-}
2module Main where
3
4import Data.Conduit.Binary
5import Data.Conduit.Network
6import Data.Conduit
7import qualified Data.Conduit.List as CL
8import qualified Data.ByteString.Char8 as S
9
10import Network.Socket (Family(..))
11import Data.HList
12import ServerC
13
14{-
15data 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
25handleConnection :: AppData IO -> IO ()
26handleConnection appdata = do
27 sourceLbs "<stream>\n" $$ appSink appdata -- send bytestring
28 appSource appdata $$ CL.mapM_ S.putStrLn -- display inbound bytestring
29
30mainOld = 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
39handleC st src snk = do
40 sourceLbs "<stream>\n" $$ snk
41 src $$ CL.mapM_ S.putStrLn
42
43mainC = do
44 doServer (AF_INET .*. 5222 .*. HNil) handleC
45 _ <- getLine
46 return ()
47
48main = mainC