-
Notifications
You must be signed in to change notification settings - Fork 0
Client
Jean-Philippe Clipffel edited this page Jan 15, 2015
·
4 revisions
A client is a process receiving and sending signals. This page explain how to use client object to start receiving and sending signals.
The Signal repository contains a sample client with a shell-like interface.
Include <libAISignal/client.hh>, and don't forget to link with the library. Before using object, you must configure network link.
AISignal::client sigclient;
// Setup network
// When calling connect(), a new received thread is started.
sigclient.set_address("127.0.0.1"); // Set signal server address
sigclient.set_port(5007); // Set signal server port
sigclient.connect(); // Connect to server - throw an error if connection fails
// Stack
// Signals are stored in a local (client-side) stack of size 20 by default.
sigclient.set_limit(42); // Set local signals stack size to 42
// Subscribe
// We'll now inform the server instance from which channels we want to receive signals.
// When subscribing to a channel, server start to send new signals immediately in receiver thread.
// Note: you can't create channels form client side.
sigclient.subscribe(".test"); // Subscribe to ".test" channel
sigclient.subscribe(".system.tests.lol"); // Subscribe to ".system.tests.lol" channel
// Receive signals
// Using fetch(), an empty signal can be returned if no new signal is available.
AISignal::signal sig; // Received signal
sig = sigclient.fetch(".test"); // Return new signal from '.test', or empty one.
sig = sigclient.fetch(".test", AISignal::mode::FIFO); // Return oldest available signal
sig = sigclient.fetch(".test", AISignal::mode::LIFO); // Return newest available signal
sig = sigclient.fetch(".test", AISignal::mode::SINGLE); // Return last received signal and delete older ones.
sig = sigclient.fetch(".smtg_else"); // Not subscribed to , will always return emtpy signal
// Sending signals
// You can send signal on all available channels. If a channel doesn't exists, signal will be discarded.
sigclient.send(".test", "hello"); // Send 'hello' on '.test'
sigclient.send(".smtg_else", "hello"); // Channel don't exists, so signal will be dropped