ePages 7.1.0 - DE_EPAGES/WebInterface/API/SequenceProtocol.pm

Package DE_EPAGES::WebInterface::API::SequenceProtocol

A simple protocol to ensure ordering and identification of queries sent via UDP

Functions

new
receive
receiveAll
send
sendReceive
sendReceiveAll

new

Creates a new SequenceProtocol object.

Syntax
$Protocol = DE_EPAGES::WebInterface::API::SequenceProtocol->new($UDPClient);
Example
$Protocol = DE_EPAGES::WebInterface::API::SequenceProtocol->new($UDPClient);
my $PacketId = $Protocol->send('Hello');
my $Response = $Protocol->receive($PacketId);
Input
$UDPClient (DE_EPAGES::Core::API::Object::UDPClient)
the network client object
Return
$Protocol (DE_EPAGES::WebInterface::API::SequenceProtocol)
protocol object

receive

Receives the response to a previously sent request identified by $PacketId

Syntax
my $Response = $SequenceProtocol->receive( $PacketId, $TimeoutSec, $MaxLength );
Input
$PacketId (string)
packet identificator returned by send()
$TimeoutSec (float)
maximum time to wait for data in seconds (default 1.0)
$MaxLength (integer)
maximum length of the received data (default 1024)
Return
$Data (string)
received data or undef if no matching packet was received

receiveAll

Receives the responses to a previously sent request identified by $PacketId

Syntax
my $Responses = $SequenceProtocol->receiveAll( $PacketId, $TimeoutSec, $MaxLength );
Input
$PacketId (string)
packet identificator returned by send()
$TimeoutSec (float)
maximum time to wait for data in seconds (default 1.0)
$MaxLength (integer)
maximum length of the received data (default 1024)
Return
$Data (ref.array.string)
received data or undef if no matching packet was received

send

Sends a message containing $Data. Prepends a message identificator to $Data.

Syntax
$PacketId = $SequenceProtocol->send( $Data );
Input
$Data (string)
bytes to send
Return
$PacketId (string)
a packet identificator that can be passed to receive()

sendReceive

Sends a message containing $Data, then waits for and returns a response

Syntax
my $Response = $SequenceProtocol->sendReceive( $Data );
Input
$Data (string)
bytes to send
Return
$Response (string)
received data or undef if no matching packet was received

sendReceiveAll

Sends a message containing $Data, then waits for and returns all responses

Syntax
my $Responses = $SequenceProtocol->sendReceiveAll( $Data );
Input
$Data (string)
bytes to send
Return
$Responses (ref.array.string)
received data or undef if no matching packet was received