| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Network.HTTP.Client.WebSockets
Description
Glue code for http-client and websockets.
This module is intended to be imported qualified.
If you want to use TLS-secured WebSockets (via the wss scheme)
you need to supply a Manager which supports TLS, for example
from http-client-tls
or http-client-openssl.
Example
>>>:set -XOverloadedStrings>>>:set -XQuasiQuotes>>>>>>import Network.HTTP.Client (Manager, defaultManagerSettings, newManager)>>>import qualified Network.WebSockets as WS>>>import qualified Network.HTTP.Client.WebSockets as HCWS>>>import Network.URI.Static>>>import Data.ByteString (ByteString)>>>>>>:{runEchoExample :: Manager -> IO ByteString runEchoExample mgr = HCWS.runClient mgr echoUri $ \conn -> do WS.sendTextData conn ("hello there" :: ByteString) _ <- WS.receiveDataMessage conn -- skip first msg msg <- WS.receiveData conn pure (msg :: ByteString) where echoUri = [uri|ws://echo.websocket.events|] -- no TLS in this example :}
>>>runEchoExample =<< newManager defaultManagerSettings"hello there"