summaryrefslogtreecommitdiff
path: root/ConduitServer.hs
blob: 0838ce26d9356cf6de58632a172c7882b0adedd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Data.Conduit.Binary
import Data.Conduit.Network
import Data.Conduit
import qualified Data.Conduit.List as CL
import qualified Data.ByteString.Char8 as S

import Network.Socket (Family(..))
import Data.HList
import ServerC

{-
data AppData m = AppData
    { appSource :: Source m ByteString
    , appSink :: Sink ByteString m ()
    , appSockAddr :: SockAddr
    , appLocalAddr :: Maybe SockAddr
    }
-}

-- handleConnection will simply output everything
-- it sees from the connection to the terminal
handleConnection :: AppData IO -> IO ()
handleConnection appdata = do
    sourceLbs "<stream>\n" $$ appSink appdata -- send bytestring
    appSource appdata $$ CL.mapM_ S.putStrLn -- display inbound bytestring

mainOld = do
    -- Listen to port 5222 and invoke handleConnection on every
    -- inbound connection.
    runTCPServer (serverSettings 5222 HostAny) handleConnection
    return ()




handleC st src snk = do
    sourceLbs "<stream>\n" $$ snk
    src $$ CL.mapM_ S.putStrLn

mainC = do
    doServer (AF_INET .*. 5222 .*. HNil) handleC
    _ <- getLine
    return ()

main = mainC