A wxClient object represents the client part of a client-server DDE (Dynamic Data Exchange) conversation (available in both Windows and UNIX).
To create a client which can communicate with a suitable server, you need to derive a class from wxConnection and another from wxClient. The custom wxConnection class will intercept communications in a 'conversation' with a server, and the custom wxServer is required so that a user-overriden wxClient::OnMakeConnection member can return a wxConnection of the required class, when a connection is made.
For example:
class MyConnection: public wxConnection { public: MyConnection(void)::wxConnection(ipc_buffer, 3999) {} ~MyConnection(void) { } Bool OnAdvise(char *topic, char *item, char *data, int size, int format) { wxMessageBox(topic, data); } }; class MyClient: public wxClient { public: MyClient(void) {} wxConnection *OnMakeConnection(void) { return new MyConnection; } };Here, MyConnection will respond to OnAdvise messages sent by the server.
When the client application starts, it must first call wxIPCInitialize before creating an instance of the derived wxClient. In the following, command line arguments are used to pass the host name (the name of the machine the server is running on) and the server name (identifying the server process). Calling wxClient::MakeConnection implicitly creates an instance of MyConnection if the request for a connection is accepted, and the client then requests an Advise loop from the server, where the server calls the client when data has changed.
wxIPCInitialize(); char *server = "4242"; char hostName[256]; wxGetHostName(hostName, sizeof(hostName)); char *host = hostName; if (argc > 1) server = argv[1]; if (argc > 2) host = argv[2]; // Create a new client MyClient *client = new MyClient; the_connection = (MyConnection *)client->MakeConnection(host, server, "IPC TEST"); if (!the_connection) { wxMessageBox("Failed to make connection to server", "Client Demo Error"); return NULL; } the_connection->StartAdvise("Item");See also wxServer, wxConnection, the chapter on interprocess communication in the user manual, and the programs in samples/ipc.