More DDE details

A wxClient object initiates the client part of a client-server DDE-like (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 receive communications in a `conversation' with a server. and the custom wxServer is required so that a user-overridden wxClient::OnMakeConnection member can return a wxConnection of the required class, when a connection is made.

For example:

class MyConnection: public wxConnection {
  MyConnection(void)::wxConnection() {}
  ~MyConnection(void) { }
  bool OnAdvise(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format)
  { wxMessageBox(topic, data); }

class MyClient: public wxClient {
  MyClient(void) {}
  wxConnectionBase *OnMakeConnection(void) { return new MyConnection; }

Here, MyConnection will respond to OnAdvise messages sent by the server by displaying a message box.

When the client application starts, it must create 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 (an Advise loop is where the server calls the client when data has changed).

  wxString server = "4242";
  wxString hostName;

  // Create a new client
  MyClient *client = new MyClient;
  connection = (MyConnection *)client->MakeConnection(hostName, server, "IPC TEST");

  if (!connection)
    wxMessageBox("Failed to make connection to server", "Client Demo Error");
    return NULL;
ymasuda 平成17年11月19日