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

IPC::UDPmsg - UDP Interprocess Communication Module

SYNOPSIS

The purpose of this package is to provide non-blocking message passing between two or more processes running on the same machine, in such a way that it will run on Win32 as well as Linux machines.

OPERATING SYSTEMS

This module has been tested on:

  • Windows 2000

  • Windows 98 (2nd edition)

  • Linux (Fedora Core 1)

DESCRIPTION

The underlying structure is based on UPD packets passed thru address 127.0.0.1 and is expected to be reliable, although this may not be true on every OS. The most important motivation for this module is have a single solution that works under Linux and Win32.

Each process is assigned a port. Each process creates an object using that port number. Passing a message from one process to another is just a matter of providing the destination port number. A process can receive messages from any other process using just the one object. So there is only one input to monitor, no matter how many other processes may be sending messages. The from() method will tell who sent the message, if that information is needed, for example to send a reply. Most important, is that the read() method is non-blocking, and returns immediately if no data is available.

Methods included are:

   $msg = IPC::Msg->new($listen_port);    # returns a new, ready to use, object
   $data = $msg->read();                  # returns the next message, or undef if none
   $msg->write($dest_port, $data);        # sends $data to the process assigned $dest_port
                                          #   If the $dest_port has not been created, the
                                          #   data will be silently lost.
   $port = $msg->from();                  # returns the port number of the process that
                                          #   sent the last message read.
   $stat = $msg->canread();               # returns true if data is available to read.
                                          #   Will sometimes return true even if no data.
                                          #   For example, if an error occurred. In this
                                          #   case, read() will still correctly return undef.
                                          #   Generally, there is no need to call this method,
                                          #   simply call the read() method instead.

Object Variables are:

    $self->{PORT}  = integer, the port we listen on
    $self->{IADDR} = packed, the internet address of local & remote
    $self->{SOCK}  = our UDP socket
    $self->{FROM}  = integer, the port of sender of the last message received

WARNINGS

This module provides no security. Any process within a machine could send a message to an open UDP port, and any machine in the Internet can send a packet to an open UDP port unless the port is otherwise blocked by another mechanism, for example a firewall. Therefore this module is best suited for machines that either stand along, and are not networked or machines that are behind firewalls. Security could be added, and will be perhaps in some future release.

AUTHOR

Robert Laughlin ( robert@galaxysys.com )

VERSIONS

  • IPC::UDPmsg version 0.12, 23 Jan 2005 README file added

  • IPC::UDPmsg version 0.11, 22 Jan 2005 Documentation improved slightly, renamed

  • IPC::UdpMsg version 0.10, 11 Jan 2005 Initial release

COPYRIGHT

Copyright (c) 2005 Robert Laughlin <robert@galaxysys.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.