Network.WebSockets.Client

websockets-0.13.0.0: A sensible and clean way to write WebSocket-capable servers in Haskell.

Safe Haskell | None
Language | Haskell2010

Network.WebSockets.Client

Contents

- Low level functionality

Description

This part of the library provides you with utilities to create WebSockets clients (in addition to servers).

Synopsis

- type ClientApp a = Connection -> IO a
- runClient :: String -> Int -> String -> ClientApp a -> IO a
- runClientWith :: String -> Int -> String -> ConnectionOptions -> Headers -> ClientApp a -> IO a
- runClientWithSocket :: Socket -> String -> String -> ConnectionOptions -> Headers -> ClientApp a -> IO a
- runClientWithStream :: Stream -> String -> String -> ConnectionOptions -> Headers -> ClientApp a -> IO a
- newClientConnection :: Stream -> String -> String -> ConnectionOptions -> Headers -> IO Connection
- createRequest :: Protocol -> ByteString -> ByteString -> Bool -> Headers -> IO RequestHead
- data Protocol = Hybi13
- defaultProtocol :: Protocol
- checkServerResponse :: Stream -> RequestHead -> IO ()
- streamToClientConnection :: Stream -> ConnectionOptions -> IO Connection

# Documentation

type ClientApp a = Connection -> IO a #

A client application interacting with a single server. Once this `IO` action finished, the underlying socket is closed automatically.

runClient #

Arguments

:: String | Host
-> Int | Port
-> String | Path
-> ClientApp a | Client application
-> IO a |

runClientWith #

Arguments

:: String | Host
-> Int | Port
-> String | Path
-> ConnectionOptions | Options
-> Headers | Custom headers to send
-> ClientApp a | Client application
-> IO a |

runClientWithSocket #

Arguments

:: Socket | Socket
-> String | Host
-> String | Path
-> ConnectionOptions | Options
-> Headers | Custom headers to send
-> ClientApp a | Client application
-> IO a |

runClientWithStream #

Arguments

:: Stream | Stream
-> String | Host
-> String | Path
-> ConnectionOptions | Connection options
-> Headers | Custom headers to send
-> ClientApp a | Client application
-> IO a |

newClientConnection #

Arguments

:: Stream | Stream that will be used by the new `Connection`.
-> String | Host
-> String | Path
-> ConnectionOptions | Connection options
-> Headers | Custom headers to send
-> IO Connection |

Build a new `Connection` from the client's point of view.

WARNING: Be sure to call `close` on the given `Stream` after you are done using the `Connection` in order to properly close the communication channel. `runClientWithStream` handles this for you, prefer to use it when possible.

# Low level functionality

createRequest :: Protocol -> ByteString -> ByteString -> Bool -> Headers -> IO RequestHead #

data Protocol #

Constructors

Hybi13 |

#### Instances

Instances details

Show Protocol # |
Instance details Defined in Network.WebSockets.Protocol Methods showsPrec :: Int -> Protocol -> ShowS # show :: Protocol -> String # showList :: [Protocol] -> ShowS #

defaultProtocol :: Protocol #

checkServerResponse :: Stream -> RequestHead -> IO () #

Check the response from the server. Throws `OtherHandshakeException` on failure

streamToClientConnection :: Stream -> ConnectionOptions -> IO Connection #

Build a `Connection` from a pre-established stream with already finished handshake.

NB: this will not perform any handshaking.