box-socket-0.5.1.0: Box websockets
Safe HaskellSafe-Inferred
LanguageGHC2021

Box.TCP.Example

Description

It's a box. It's a TCP socket. It's an example.

Synopsis

Documentation

>>> :set -XOverloadedStrings
>>> import Box
>>> import Box.TCP.Example
>>> import Control.Concurrent.Async

senderExample :: [ByteString] -> IO [ByteString] Source #

A server that only sends and a client that only receives.

The result here is indeterminate: it can return ["ab"] or ["a","b"] depending on when the client and servers fire.

senderExample ["a","b"]
"ab"

senderLinesExample :: [Text] -> IO [Text] Source #

A server that only sends and a client that only receives.

>>> senderLinesExample ["a","b"]
["a","b"]

echoExample :: [ByteString] -> IO [ByteString] Source #

echo server example

>>> echoExample ["a","b","c"]
["echo: abc"]

clientIO :: IO () Source #

"q" to close the client, reads and writes from std

>>> clientIO
*** Exception: Network.Socket.connect: <socket: ...>: does not exist (Connection refused)

serverIO :: IO () Source #

"q" to close a client socket down. Ctrl-c to close the server. Reads and writes from std.

>>> a <- async serverIO
>>> serverIO
*** Exception: Network.Socket.bind: resource busy (Address already in use)
>>> cancel a