-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.hs
More file actions
28 lines (22 loc) · 796 Bytes
/
Server.hs
File metadata and controls
28 lines (22 loc) · 796 Bytes
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
module Main where
import Control.Monad (forever)
import Network.HTTP.Types (status200)
import qualified Network.WebSockets as WS
import qualified Network.Wai as Wai
import qualified Network.Wai.Handler.Warp as Warp
import qualified Network.Wai.Handler.WebSockets as WaiWS
import Echo
main :: IO ()
main = do
putStrLn "started echo on port 9160"
Warp.run 9160 $
WaiWS.websocketsOr WS.defaultConnectionOptions wsapp backapp
wsapp :: WS.ServerApp
wsapp pending = WS.acceptRequest pending >>= talk
backapp :: Wai.Application
backapp _ respond = respond $
Wai.responseLBS status200 [("Content-Type", "text/plain")] "Hello World"
talk :: WS.Connection -> IO ()
talk conn = forever $ do
msg <- WS.receiveData conn
WS.sendTextData conn $ echo msg