]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tipc.tex
ODBC updates
[wxWidgets.git] / docs / latex / wx / tipc.tex
CommitLineData
a660d684
KB
1\section{Interprocess communication overview}\label{ipcoverview}
2
3Classes: \helpref{wxDDEServer}{wxddeserver}, \helpref{wxDDEConnection}{wxddeconnection},
4\rtfsp\helpref{wxDDEClient}{wxddeclient}.
5
6TODO: rewrite.
7
8The following describes how wxWindows implements DDE. The following
9three classes are central.
10
11\begin{enumerate}\itemsep=0pt
12\item wxDDEClient. This represents the client application, and is used
13only within a client program.
14\item wxDDEServer. This represents the server application, and is used
15only within a server program.
16\item wxDDEConnection. This represents the connection from the current
17client or server to the other application (server or client), and can be used
18in both server and client programs. Most DDE
19transactions operate on this object.
20\end{enumerate}
21
22Messages between applications are usually identified by three variables:
23connection object, topic name and item name. A data string is a fourth
24element of some messages. To create a connection (a conversation in
25Windows parlance), the client application sends the message
26MakeConnection to the client object, with a string service name to
27identify the server and a topic name to identify the topic for the
28duration of the connection. Under UNIX, the service name must contain an
29integer port identifier.
30
31The server then responds and either vetos the connection or allows it.
32If allowed, a connection object is created which persists until the
33connection is closed. The connection object is then used for subsequent
34messages between client and server.
35
36To create a working server, the programmer must:
37
38\begin{enumerate}\itemsep=0pt
39\item Derive a class from wxDDEServer.
40\item Override the handler OnAcceptConnection for accepting or rejecting a connection,
41on the basis of the topic argument. This member must create and return a connection
42object if the connection is accepted.
43\item Create an instance of your server object, and call Create to
44activate it, giving it a service name.
45\item Derive a class from wxDDEConnection.
46\item Provide handlers for various messages that are sent to the server
47side of a wxDDEConnection.
48\end{enumerate}
49
50To create a working client, the programmer must:
51
52\begin{enumerate}\itemsep=0pt
53\item Derive a class from wxDDEClient.
54\item Override the handler OnMakeConnection to create and return
55an appropriate connection object.
56\item Create an instance of your client object.
57\item Derive a class from wxDDEConnection.
58\item Provide handlers for various messages that are sent to the client
59side of a wxDDEConnection.
60\item When appropriate, create a new connection by sending a MakeConnection
61message to the client object, with arguments host name (processed in UNIX only),
62service name, and topic name for this connection. The client object will call OnMakeConnection
63to create a connection object of the desired type.
64\item Use the wxDDEConnection member functions to send messages to the server.
65\end{enumerate}
66
67\subsection{Data transfer}
68
69These are the ways that data can be transferred from one application to
70another.
71
72\begin{itemize}\itemsep=0pt
73\item {\bf Execute:} the client calls the server with a data string representing
74a command to be executed. This succeeds or fails, depending on the
75server's willingness to answer. If the client wants to find the result
76of the Execute command other than success or failure, it has to explicitly
77call Request.
78\item {\bf Request:} the client asks the server for a particular data string
79associated with a given item string. If the server is unwilling to
80reply, the return value is NULL. Otherwise, the return value is a string
81(actually a pointer to the connection buffer, so it should not be
82deallocated by the application).
83\item {\bf Poke:} The client sends a data string associated with an item
84string directly to the server. This succeeds or fails.
85\item {\bf Advise:} The client asks to be advised of any change in data
86associated with a particular item. If the server agrees, the server will
87send an OnAdvise message to the client along with the item and data.
88\end{itemize}
89
90The default data type is wxCF\_TEXT (ASCII text), and the default data
91size is the length of the null-terminated string. Windows-specific data
92types could also be used on the PC.
93
94\subsection{Examples}
95
96See the sample programs {\it server}\/ and {\it client}\/ in the IPC
97samples directory. Run the server, then the client. This demonstrates
98using the Execute, Request, and Poke commands from the client, together
99with an Advise loop: selecting an item in the server list box causes
100that item to be highlighted in the client list box.
101
102See also the source for wxHelp, which is a DDE server, and the files
103wx\_help.h and wx\_help.cc which implement the client interface to
104wxHelp.
105
106\subsection{More DDE details}
107
108A wxDDEClient object represents the client part of a client-server DDE
109(Dynamic Data Exchange) conversation (available in both
110Windows and UNIX).
111
112To create a client which can communicate with a suitable server,
113you need to derive a class from wxDDEConnection and another from wxDDEClient.
114The custom wxDDEConnection class will intercept communications in
115a `conversation' with a server, and the custom wxDDEServer is required
116so that a user-overriden \helpref{wxDDEClient::OnMakeConnection}{wxddeclientonmakeconnection} member can return
117a wxDDEConnection of the required class, when a connection is made.
118
119For example:
120
121\begin{verbatim}
122class MyConnection: public wxDDEConnection
123{
124 public:
125 MyConnection(void)::wxDDEConnection(ipc_buffer, 3999) {}
126 ~MyConnection(void) { }
127 Bool OnAdvise(char *topic, char *item, char *data, int size, int format)
128 { wxMessageBox(topic, data); }
129};
130
131class MyClient: public wxDDEClient
132{
133 public:
134 MyClient(void) {}
135 wxDDEConnection *OnMakeConnection(void) { return new MyConnection; }
136};
137
138\end{verbatim}
139
140Here, {\bf MyConnection} will respond to \helpref{OnAdvise}{wxddeconnectiononadvise} messages sent
141by the server.
142
143When the client application starts, it must first call \helpref{wxIPCInitialize}{wxipcinitialize}\rtfsp
144before creating an instance of the derived wxDDEClient. In the following, command line
145arguments are used to pass the host name (the name of the machine the server is running
146on) and the server name (identifying the server process). Calling \helpref{wxDDEClient::MakeConnection}{wxddeclientmakeconnection}\rtfsp
147implicitly creates an instance of {\bf MyConnection} if the request for a
148connection is accepted, and the client then requests an {\it Advise} loop
149from the server, where the server calls the client when data has changed.
150
151\begin{verbatim}
152 wxIPCInitialize();
153
154 char *server = "4242";
155 char hostName[256];
156 wxGetHostName(hostName, sizeof(hostName));
157
158 char *host = hostName;
159
160 if (argc > 1)
161 server = argv[1];
162 if (argc > 2)
163 host = argv[2];
164
165 // Create a new client
166 MyClient *client = new MyClient;
167 the_connection = (MyConnection *)client->MakeConnection(host, server, "IPC TEST");
168
169 if (!the_connection)
170 {
171 wxMessageBox("Failed to make connection to server", "Client Demo Error");
172 return NULL;
173 }
174 the_connection->StartAdvise("Item");
175\end{verbatim}
176
177