I'm messing around with WebSockets and I have written an "echo server" which I expected to log to the console as it runs:
echo = Warp.run 3000 app
where
app = WS.websocketsOr
WS.defaultConnectionOptions
wsApp
httpApp
httpApp _ respond = do
put "HTTP Request Recieved"
respond $ Wai.responseFile
Http.status200
[]
"web/index.html"
Nothing
wsApp :: WS.ServerApp
wsApp pendingConn = do
conn <- WS.acceptRequest pendingConn
WS.forkPingThread conn 30
put "WebSocket Connection Open"
listen conn
listen :: WS.Connection -> IO ()
listen conn = forever $ do
str <- WS.receiveData conn :: (IO Text.Text)
put $ Text.unpack str
WS.sendTextData conn str
main :: IO ()
main = do
put "Echo WebSocket Running ..."
echo
put str = hPutStrLn stdout str >> hFlush stdout
As you can see, I've tried flushing stdout
but with no success. I get
$ ./echoServer
Echo WebSocket Running ...
but nothing more. Even though I can successfully load "web/index.html" in a browser and successfully establish a connection to the WebSocket and use it, I get no feedback from the console.
What do I need to do to get output to the console?
Library Versions:
- Warp : 3.2.13
- WAI : 3.2.1.1
- wai-websockets : 3.0.1.1
- websockets : 0.12.2.0