remotion-0.2.0: A library for client-server applications based on custom protocols

Safe HaskellNone

Remotion.Server

Contents

Synopsis

Control

Monad-transformer

data Server m a Source

A monad transformer, which runs the server in the background.

Instances

MonadTrans Server 
MonadTransControl Server 
MonadBase IO m => MonadBase IO (Server m) 
MonadBaseControl IO m => MonadBaseControl IO (Server m) 
Monad m => Monad (Server m) 
Functor m => Functor (Server m) 
Applicative m => Applicative (Server m) 
MonadIO m => MonadIO (Server m) 

run :: (Serializable IO i, Serializable IO o, MonadIO m) => Settings i o s -> Server m a -> m (Either Failure a)Source

Run the server, while automatically managing all related resources.

wait :: MonadIO m => Server m ()Source

Block until the server stops (which should never happen).

countSlots :: MonadIO m => Server m IntSource

Count the currently available slots for new connections.

Simple

runAndWait :: (Serializable IO i, Serializable IO o) => Settings i o s -> IO (Either Failure ())Source

Run the server, while blocking the calling thread.

Settings

type Settings i o s = (UserProtocolSignature, ListeningMode, Timeout, MaxClients, Log, ProcessUserRequest i o s)Source

Settings of how to run the server.

type UserProtocolSignature = ByteStringSource

A unique identification of user's protocol version used for checking of protocol versions mismatch between client and server. It can be simply a user-supplied version number or a hash or a serialization of the representation of a type used for protocol, which can be generated using such library as type-structure.

data ListeningMode Source

Defines how to listen for connections.

Constructors

Host Port Authenticate

Listen on a port with an authentication function.

Socket FilePath

Listen on a socket file. Since sockets are local no authentication is needed. Works only on UNIX systems.

type Port = IntSource

A port to run the server on.

type Authenticate = Credentials -> IO BoolSource

A function, which checks the authentication data. If you want to provide access to anybody, use (const $ return True).

type Credentials = Maybe ByteStringSource

Either a plain ASCII password or an encoding of some data, e.g. an MD5 hash of a username-password pair or just a password. In more involved scenarios you can mix in serialization, e.g. a serialized pair of username and a hash of just the password.

Nothing means anonymous.

type Timeout = IntSource

A session timeout in microseconds. The period of keepalive signaling depends on that parameter. If you don't want excessive requests, just make it a couple of minutes.

type MaxClients = IntSource

A maximum amount of clients. When this amount is reached the server rejects all the further connections.

type Log = Text -> IO ()Source

A logging function. If you want no logging, use (const $ return ()). If you want to output to console use Data.Text.IO.putStrLn. If you want to somehow reformat the output, you're welcome: (Data.Text.IO.putStrLn . ("Remotion.Server: " <>)).

type ProcessUserRequest i o s = State s -> i -> IO oSource

A function which processes requests of type i from client and produces a response of type o, while maintaining a user-defined session state of type s per each client.

This function essentially is what defines what the server actually does.

type State s = IORef (Maybe s)Source

A mutable state associated with particular client's connection. Since we're in IO anyway, we use a mutable state with IORef wrapper. You're free to extend it with whatever the data structure you want.

Failure

data Failure Source

A Server failure.

Constructors

ListeningSocketIsBusy 

Instances

Eq Failure 
Show Failure 
Typeable Failure 
Generic Failure