diff --git a/Server.hs b/Webserver.hs similarity index 97% rename from Server.hs rename to Webserver.hs index d5e4e06..645a5d1 100644 --- a/Server.hs +++ b/Webserver.hs @@ -1,4 +1,4 @@ -module Server where +module Main where import Network.Loli import Network.Loli.Utils @@ -53,7 +53,8 @@ jsonResults = encode . (Prelude.map toJSO) . sortBySnd where -- FIXME sorting co -- server main = do c <- classifier - (run 3000) . loli $ do + print "Server starting at port 3000" + (run 3000) . loli $ do get "/env" $ do env <- ask diff --git a/Websockets b/Websockets new file mode 100755 index 0000000..0a91e3c Binary files /dev/null and b/Websockets differ diff --git a/Websockets.hs b/Websockets.hs new file mode 100644 index 0000000..79fc70f --- /dev/null +++ b/Websockets.hs @@ -0,0 +1,24 @@ +import Network +import qualified Network.Websocket as WS + +config = WS.Config { + WS.configPort = 9876, + WS.configOrigins = Nothing, + WS.configDomains = Nothing, + WS.configOnOpen = onOpen, + WS.configOnMessage = onMessage, + WS.configOnClose = onClose + } + +main = withSocketsDo $ WS.startServer config + + +onOpen ws = do + putStrLn "Connection opened" + +onMessage ws msg = do + putStrLn $ "Received message: " ++ msg + WS.send ws msg + +onClose ws = do + putStrLn "Connection closed" \ No newline at end of file diff --git a/Websockets.html b/Websockets.html new file mode 100644 index 0000000..b9ba91d --- /dev/null +++ b/Websockets.html @@ -0,0 +1,48 @@ + + + Web Sockets + + + + + + + + +

Websockets example

+ +
+
+ +
+
+ + \ No newline at end of file