Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data WebSocket
- data WebSocketPending
Documentation
Endpoint for defining a route to provide a web socket. The
handler function gets an already negotiated websocket Connection
to send and receive data.
Example:
type WebSocketApi = "stream" :> WebSocket server :: Server WebSocketApi server = streamData where streamData :: MonadIO m => Connection -> m () streamData c = do liftIO $ forkPingThread c 10 liftIO . forM_ [1..] $ \i -> do sendTextData c (pack $ show (i :: Int)) >> threadDelay 1000000
data WebSocketPending Source #
Endpoint for defining a route to provide a web socket. The
handler function gets a PendingConnection
. It can either
rejectRequest
or acceptRequest
. This function is provided
for greater flexibility to reject connections.
Example:
type WebSocketApi = "stream" :> WebSocketPending server :: Server WebSocketApi server = streamData where streamData :: MonadIO m => PendingConnection -> m () streamData pc = do c <- acceptRequest pc liftIO $ forkPingThread c 10 liftIO . forM_ [1..] $ \i -> sendTextData c (pack $ show (i :: Int)) >> threadDelay 1000000
Instances
HasServer WebSocketPending ctx Source # | |
Defined in Servant.API.WebSocket type ServerT WebSocketPending m :: Type # route :: Proxy WebSocketPending -> Context ctx -> Delayed env (Server WebSocketPending) -> Router env # hoistServerWithContext :: Proxy WebSocketPending -> Proxy ctx -> (forall x. m x -> n x) -> ServerT WebSocketPending m -> ServerT WebSocketPending n # | |
type ServerT WebSocketPending m Source # | |
Defined in Servant.API.WebSocket |