Inter-Process Communication

From Wx version 0.9921 the Inter-Process Communication classes wxConnection, wxServer and wxClient are available in wxPerl.

Note: For MS Windows platforms you will need wxWidgets built with Alien::wxWidgets 0.64 or later. Prior versions of Alien::wxWidgets did not build Alien::wxWidgets with IPC support.

The wxWidgets IPC classes work using DDE on MS Windows and sockets on other platforms. When using the sockets based implementation you can ( and should ) use UNIX sockets rather than INET sockets.

The base reference is the current wxWidgets documentation for Inter-Process Communication.

The wxPerl implementation has some slight differences to the C++ implementation to accommodate more Perl-like usage. For example, you are not required to pass the size of data buffers in the Perl implementation.

IPC Server

To add IPC server capabilities to your wxPerl application you must:

Create one or more classes derived from Wx::Connection and override the following methods:

  • OnDisconnect -  if you want to run code when a client disconnects.
  • OnExecute - if you want to respond when a client calls the Execute method. If you are using wxWidgets 2.9.4 or greater you may choose to override the OnExec method instead.
  • OnPoke - if you want to respond when a client calls the Poke method.
  • OnRequest - if you want to respond when a client calls the Request method.
  • OnStartAdvise - if your server will push data to clients using the Advise method.
  • OnStopAdvise - if your server will push data to clients using the Advise method.
Create at least on class derived from Wx::Server and override the following method:
  • OnAcceptConnection - return an instance of one of your Wx::Connection derived classes.

IPC Client 

To add IPC client capabilities to your wxPerl application you must:

Create one or more classes derived from Wx::Connection and override the following methods:
  • OnDisconnect - if you want to run code when the server disconnects.
  • OnAdvise - if you want to receive messages from the server after calling StartAdvise
Create at least one class derived from Wx::Client and override the following method:
  • OnMakeConnection - return an instance of one of your Wx::Connection derived classes.
Example Code

The example ipcserver.pl script contains code for both a client and a server application demonstration use of all the IPC methods.

Wx::IPC

To use the IPC classes you must load the IPC module:

use Wx::IPC;

Apart from the three IPC classes, Wx::Connection, Wx::Server and Wx::Client, the module also provides the wxIPCFormat constants to Wx.

use Wx qw( :ipc );

exports the following wxIPCFormat constants

wxIPC_INVALID
wxIPC_TEXT
wxIPC_BITMAP
wxIPC_METAFILE
wxIPC_SYLK
wxIPC_DIF
wxIPC_TIFF
wxIPC_OEMTEXT
wxIPC_DIB
wxIPC_PALETTE
wxIPC_PENDATA
wxIPC_RIFF
wxIPC_WAVE
wxIPC_UNICODETEXT
wxIPC_ENHMETAFILE
wxIPC_FILENAME
wxIPC_LOCALE
wxIPC_UTF16TEXT
wxIPC_UTF8TEXT
wxIPC_UTF32TEXT
wxIPC_PRIVATE

Notes: For wxWidgets 2.8.12 wxIPC_UTF16TEXT, wxIPC_UTF8TEXT and wxIPC_UTF32TEXT are just synonyms for wxIPC_UNICODETEXT.   On MS Windows the DDE backend will usually ignore your settings and return everything as text. This does not appear to affect the actual data though.

Wx::Connection Methods

my $con = Wx::Connection->new;

$bool = $con->Advise($item, $data, $format = wxIPC_TEXT);

$bool = $con->Execute($data, $format = wxIPC_TEXT);

$bool = $con->Poke($item, $data, $format = wxIPC_TEXT);

$data = $con->Request($item, $format = wxIPC_TEXT);


$bool = $con->StartAdvise($item);

$bool = $con->StopAdvise($item);

$bool = $con->Disconnect();


$bool = OnAdvise($topic, $item, $data, $format);

$bool = OnDisconnect();

$bool = OnExecute($topic, $data, $format);

$bool = OnExec($topic, $data);

$bool = OnPoke($topic, $item, $data, $format);

$data = OnRequest($topic, $item, $format);

$bool = OnStartAdvise($topic, $item);

$bool = OnStopAdvise($topic, $item);


Wx::Server  Methods

my $srv = Wx::Server->new;

$bool = $srv->Create($servicename);

Wx::Connection = OnAcceptConnection( $topic );

Wx::Client Methods

my $cli = Wx::Client->new;

Wx::Connection = $cli->MakeConnection($host, $service, $topic);

Wx::Connection = OnMakeConnection();