The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Net::Layers::Datalink::Message - Perl extension for packaging and unpackaging a message.

SYNOPSIS

  use Net::Layers::Datalink::Message;

  # packaging a message

  my $msg = Net::Layers::Datalink::Message->new(message=>"Hi Mom",message_id=>1);
  &send $msg->toString();  

  # unpackaging a message

  my $msg = Net::Layers::Datalink::Message->new();
  $isValid=$msg->setMessageFromString($recievedString);
  if ($isValid)
    {
      my $messageID = $msg->getMessageID();
      my $message = $msg->getMessage();
      print "MessageID: $messageID Message: $message()";
    }

DESCRIPTION

This module has two modes. One is used for sending messages and the second mode is used for reciving messages.

The first mode is accepts a message and message id. The function toString is next called. The function toString prepends to a string an MD5 digest of the message and the message id, and returns the new string.

The second mode is called by using the setMessageFromString function as shown above. The recieved string is parsed. The subroutine checks for a valid MD5 hash of the message and message id. If everything is ok, the return value of the setMessageFunction is one, otherwise it is zero. The message and message id are available from seperate functions.

DETAILS

$msg = Net::Layers::Datalink::Message->new();

Returns a new Datalink Message object. (The new method is called this way only when a message has been recieved.)

$msg = Net::Layers::Datalink::Message->new(message=>"Hi Dad",message_id=>2);

Returns a new Datalink Message object with the message "Hi Dad", and a message_id of 2. (This new method is only called when a message is about to be sent.) ****WARNING**** All message id's must not exceed 8 digits eg: 12345678 is a valid message id while 123456789 is NOT.

The message header (md5 checksum && message id) takes up 42 bits. (Coincidence I swear!)

&send $msg->toString();

The function toString returns the message, with a prepended MD5 digest of the orignal message and the message id.

$isValid=$msg->setMessageFromString($recievedString);

The function returns 1 or 0 if the string matches the form of the toString method above. The subroutine checks for a valid MD5 hash of the message and message id.

$msg->getMessage();

Returns the orignal message.

$msg->getMessageID();

Returns the orignal message ID.

AUTHOR

Zachary Zebrowski, zak@freeshell.org

SEE ALSO

Net::Layers::Datalink::ReliableMultiSend

Net::Layers::Physical::Unreliable

Effective Perl Programming by Joseph N. Hall with Randl L. Schwartz

Computer Networks by Andrew Anenbaum