network-simple-ws-0.1: Simple interface to WebSockets.

Safe HaskellNone
LanguageHaskell98

Network.Simple.WS

Contents

Description

Simple tools for establishing and using insecure WebSockets connections on top of TCP (i.e, ws://).

See the network-simple-wss package for Secure WebSockets (i.e, wss://) support.

Notice that, currently, this is package offers tools that are mostly intreresting from a client's point of view. Server side support will come later.

Synopsis

Documentation

send :: MonadIO m => Connection -> ByteString -> m () Source #

Send bytes to the remote end.

Takes a lazy ByteString.

recv :: MonadIO m => Connection -> m ByteString Source #

Receive bytes from the remote end.

Returns a strict ByteString.

Returns an empty string when the remote end gracefully closes the connection.

Client side

connect Source #

Arguments

:: (MonadIO m, MonadMask m) 
=> HostName

WebSockets server host name (e.g., "www.example.com" or IP address).

-> ServiceName

WebSockets server port (e.g., "443" or "www").

-> ByteString

WebSockets resource (e.g., "/foo/qux?bar=wat&baz").

Leading '/' is optional.

-> [(ByteString, ByteString)]

Extra HTTP Headers (e.g., [("Authorization", "Basic dXNlcjpwYXNzd29yZA==")]).

-> ((Connection, SockAddr) -> m r)

Computation to run after establishing a WebSockets to the remote server. Takes the WebSockets connection and remote end address.

-> m r 

Connect to the specified WebSockets server.

connectSOCKS5 Source #

Arguments

:: (MonadIO m, MonadMask m) 
=> HostName

SOCKS5 proxy server hostname or IP address.

-> ServiceName

SOCKS5 proxy server service port name or number.

-> HostName

Destination WebSocket server hostname or IP address. We connect to this host through the SOCKS5 proxy specified in the previous arguments.

Note that if hostname resolution on this HostName is necessary, it will happen on the proxy side for security reasons, not locally.

-> ServiceName

Destination WebSockets server port (e.g., "443" or "www").

-> ByteString

WebSockets resource (e.g., "/foo/qux?bar=wat&baz").

Leading '/' is optional.

-> [(ByteString, ByteString)]

Extra HTTP Headers (e.g., [("Authorization", "Basic dXNlcjpwYXNzd29yZA==")]).

-> ((Connection, SockAddr, SockAddr) -> m r)

Computation taking a Connection for communicating with the destination WebSockets server through the SOCKS5 server, the address of that SOCKS5 server, and the address of the destination WebSockets server, in that order.

-> m r 

Like connect, but connects to the destination server through a SOCKS5 proxy.

Low level

clientConnectionFromStream Source #

Arguments

:: MonadIO m 
=> Stream

Stream on which to establish the WebSockets connection.

-> HostName

WebSockets server host name (e.g., "www.example.com" or IP address).

-> ServiceName

WebSockets server port (e.g., "443" or "www").

-> ByteString

WebSockets resource (e.g., "/foo/qux?bar=wat&baz").

Leading '/' is optional.

-> [(ByteString, ByteString)]

Extra HTTP Headers (e.g., [("Authorization", "Basic dXNlcjpwYXNzd29yZA==")]).

-> m Connection

Established WebSockets connection

Obtain a Connection to the specified Uri over the given Stream, connected to either a WebSockets server, or a Secure WebSockets server.

streamFromSocket :: MonadIO m => Socket -> m Stream Source #

Obtain a Stream implemented using the network Socket. You can use the network-simple library to get one of those.