blob: 4b28194e256f0af98602dfefb852e37291f83f00 (
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
|
{-# 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 qualified Data.ByteString.Lazy.Char8 as L
{-
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
main = do
-- Listen to port 5222 and invoke handleConnection on every
-- inbound connection.
runTCPServer (serverSettings 5222 HostAny) handleConnection
return ()
|