Skip to content

Instantly share code, notes, and snippets.

@deadfoxygrandpa
Created August 29, 2014 17:27
Show Gist options
  • Save deadfoxygrandpa/2a19ea0d5d55b90017e6 to your computer and use it in GitHub Desktop.
Save deadfoxygrandpa/2a19ea0d5d55b90017e6 to your computer and use it in GitHub Desktop.
WebSockets
import WebSocket as WS
inputs = constant ""
socket = WS.connect "ws://127.0.0.1" inputs
tests = count socket
main = (\a b-> asText a `above` asText b) <~ socket ~ tests
import qualified Network.WebSockets as WS
import Control.Monad (forever)
import Control.Concurrent (threadDelay, forkIO)
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as BSC
application :: WS.ServerApp
application pendingConnection = do
connection <- WS.acceptRequest pendingConnection
forever $ do
WS.sendPing connection $ BSC.pack "ping"
WS.receive connection >>= print
WS.sendTextData connection (T.pack "testing...")
threadDelay $ 10 * 1000000
main = WS.runServer "127.0.0.1" 80 application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment