- // Create the main frame window
- frame = new MyFrame(NULL, "Client", wxPoint(400, 0), wxSize(400, 300));
-
- // Give it an icon
- frame->SetIcon(wxICON(mondrian));
-
- // Make a menubar
- wxMenu *file_menu = new wxMenu;
-
- file_menu->Append(CLIENT_EXECUTE, "Execute");
- file_menu->Append(CLIENT_REQUEST, "Request");
- file_menu->Append(CLIENT_POKE, "Poke");
- file_menu->Append(CLIENT_QUIT, "Quit");
-
- wxMenuBar *menu_bar = new wxMenuBar;
-
- menu_bar->Append(file_menu, "File");
-
- // Associate the menu bar with the frame
- frame->SetMenuBar(menu_bar);
-
- // Make a panel
- frame->panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 250));
- the_list = new wxListBox(frame->panel, CLIENT_LISTBOX, wxPoint(5, 5), wxSize(150, 120));
- the_list->Append("Apple");
- the_list->Append("Pear");
- the_list->Append("Orange");
- the_list->Append("Banana");
- the_list->Append("Fruit");
-
- frame->panel->Fit();
- frame->Fit();
-
- wxString server = "4242";
-
-#if wxUSE_DDE_FOR_SAMPLE
- wxString hostName = wxGetHostName();
-#else
- wxString hostName = "localhost";
-#endif
-
- if (argc > 1)
- server = argv[1];
- if (argc > 2)
- hostName = argv[2];
-
- // Create a new client
- my_client = new MyClient;
- the_connection = (MyConnection *)my_client->MakeConnection(hostName, server, "IPC TEST");
-
- if (!the_connection)
- {
- wxMessageBox("Failed to make connection to server", "Client Demo Error");
-#ifdef __WXMSW__
-// extern void wxPrintDDEError();
-// wxPrintDDEError();
-#endif
- return FALSE;
- }
- if (!the_connection->StartAdvise("Item"))
- wxMessageBox("StartAdvise failed", "Client Demo Error");
-
- frame->Show(TRUE);
+ // service name (DDE classes) or port number (TCP/IP based classes)
+ wxString service = IPC_SERVICE;
+
+ // ignored under DDE, host name in TCP/IP based classes
+ wxString hostName = _T("localhost");
+
+ if (argc > 1)
+ service = argv[1];
+ if (argc > 2)
+ hostName = argv[2];
+
+ // Create a new client
+ my_client = new MyClient;
+
+ // suppress the log messages from MakeConnection()
+ {
+ wxLogNull nolog;
+ the_connection = (MyConnection *)
+ my_client->MakeConnection(hostName, service, IPC_TOPIC);
+
+ while ( !the_connection )
+ {
+ if ( wxMessageBox(_T("Failed to make connection to server.\nRetry?"),
+ _T("Client Demo Error"),
+ wxICON_ERROR | wxYES_NO | wxCANCEL ) != wxYES )
+ {
+ // no server
+ return FALSE;
+ }
+
+ the_connection = (MyConnection *)my_client->MakeConnection(hostName, service, _T("IPC TEST"));
+ }
+ }
+
+ if (!the_connection->StartAdvise(IPC_ADVISE_NAME))
+ wxMessageBox(_T("StartAdvise failed"), _T("Client Demo Error"));
+
+ // Create the main frame window
+ (new MyFrame(NULL, _T("Client")))->Show(TRUE);