]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sckipc.h | |
3 | // Purpose: documentation for wxTCPServer class | |
4 | // Author: wxWidgets team | |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxTCPServer | |
11 | @wxheader{sckipc.h} | |
7c913512 | 12 | |
23324ae1 FM |
13 | A wxTCPServer object represents the server part of a client-server conversation. |
14 | It emulates a DDE-style protocol, but uses TCP/IP which is available on most | |
15 | platforms. | |
7c913512 | 16 | |
23324ae1 | 17 | A DDE-based implementation for Windows is available using wxDDEServer. |
7c913512 | 18 | |
23324ae1 FM |
19 | @library{wxnet} |
20 | @category{FIXME} | |
7c913512 | 21 | |
23324ae1 FM |
22 | @seealso |
23 | wxTCPClient, wxTCPConnection, @ref overview_ipcoverview "IPC overview" | |
24 | */ | |
25 | class wxTCPServer : public wxObject | |
26 | { | |
27 | public: | |
28 | /** | |
29 | Constructs a server object. | |
30 | */ | |
31 | wxTCPServer(); | |
32 | ||
33 | /** | |
34 | Registers the server using the given service name. Under Unix, the | |
35 | string must contain an integer id which is used as an Internet port | |
36 | number. @false is returned if the call failed (for example, the port | |
37 | number is already in use). | |
38 | */ | |
39 | bool Create(const wxString& service); | |
40 | ||
41 | /** | |
42 | When a client calls @b MakeConnection, the server receives the | |
43 | message and this member is called. The application should derive a | |
44 | member to intercept this message and return a connection object of | |
45 | either the standard wxTCPConnection type, or of a user-derived type. If the | |
46 | topic is "STDIO'', the application may wish to refuse the connection. | |
47 | Under Unix, when a server is created the OnAcceptConnection message is | |
48 | always sent for standard input and output. | |
49 | */ | |
4cc4bfaf | 50 | virtual wxConnectionBase* OnAcceptConnection(const wxString& topic); |
23324ae1 FM |
51 | }; |
52 | ||
53 | ||
54 | /** | |
55 | @class wxTCPClient | |
56 | @wxheader{sckipc.h} | |
7c913512 | 57 | |
23324ae1 FM |
58 | A wxTCPClient object represents the client part of a client-server conversation. |
59 | It emulates a DDE-style protocol, but uses TCP/IP which is available on most | |
60 | platforms. | |
7c913512 | 61 | |
23324ae1 | 62 | A DDE-based implementation for Windows is available using wxDDEClient. |
7c913512 | 63 | |
23324ae1 FM |
64 | To create a client which can communicate with a suitable server, |
65 | you need to derive a class from wxTCPConnection and another from wxTCPClient. | |
66 | The custom wxTCPConnection class will intercept communications in | |
67 | a 'conversation' with a server, and the custom wxTCPServer is required | |
68 | so that a user-overridden wxTCPClient::OnMakeConnection member can return | |
69 | a wxTCPConnection of the required class, when a connection is made. | |
7c913512 | 70 | |
23324ae1 FM |
71 | @library{wxnet} |
72 | @category{FIXME} | |
7c913512 | 73 | |
23324ae1 FM |
74 | @seealso |
75 | wxTCPServer, wxTCPConnection, @ref overview_ipcoverview "Interprocess | |
76 | communications overview" | |
77 | */ | |
78 | class wxTCPClient : public wxObject | |
79 | { | |
80 | public: | |
81 | /** | |
82 | Constructs a client object. | |
83 | */ | |
84 | wxTCPClient(); | |
85 | ||
86 | /** | |
87 | Tries to make a connection with a server specified by the host | |
88 | (a machine name under Unix), service name (must | |
89 | contain an integer port number under Unix), and a topic string. If the | |
90 | server allows a connection, a wxTCPConnection object will be returned. | |
91 | The type of wxTCPConnection returned can be altered by overriding | |
92 | the OnMakeConnection() member to return your own | |
93 | derived connection object. | |
94 | */ | |
4cc4bfaf FM |
95 | wxConnectionBase* MakeConnection(const wxString& host, |
96 | const wxString& service, | |
97 | const wxString& topic); | |
23324ae1 FM |
98 | |
99 | /** | |
100 | The type of wxTCPConnection returned from a MakeConnection() call can | |
101 | be altered by deriving the @b OnMakeConnection member to return your | |
102 | own derived connection object. By default, a wxTCPConnection | |
103 | object is returned. | |
23324ae1 FM |
104 | The advantage of deriving your own connection class is that it will |
105 | enable you to intercept messages initiated by the server, such | |
106 | as wxTCPConnection::OnAdvise. You may also want to | |
107 | store application-specific data in instances of the new class. | |
108 | */ | |
4cc4bfaf | 109 | wxConnectionBase* OnMakeConnection(); |
23324ae1 FM |
110 | |
111 | /** | |
112 | Returns @true if this is a valid host name, @false otherwise. | |
113 | */ | |
114 | bool ValidHost(const wxString& host); | |
115 | }; | |
116 | ||
117 | ||
118 | /** | |
119 | @class wxTCPConnection | |
120 | @wxheader{sckipc.h} | |
7c913512 | 121 | |
23324ae1 FM |
122 | A wxTCPClient object represents the connection between a client and a server. |
123 | It emulates a DDE-style protocol, but uses TCP/IP which is available on most | |
124 | platforms. | |
7c913512 | 125 | |
23324ae1 | 126 | A DDE-based implementation for Windows is available using wxDDEConnection. |
7c913512 | 127 | |
23324ae1 FM |
128 | A wxTCPConnection object can be created by making a connection using a |
129 | wxTCPClient object, or by the acceptance of a connection by a | |
130 | wxTCPServer object. The bulk of a conversation is controlled by | |
131 | calling members in a @b wxTCPConnection object or by overriding its | |
132 | members. | |
7c913512 | 133 | |
23324ae1 FM |
134 | An application should normally derive a new connection class from |
135 | wxTCPConnection, in order to override the communication event handlers | |
136 | to do something interesting. | |
7c913512 | 137 | |
23324ae1 FM |
138 | @library{wxnet} |
139 | @category{FIXME} | |
7c913512 | 140 | |
23324ae1 FM |
141 | @seealso |
142 | wxTCPClient, wxTCPServer, @ref overview_ipcoverview "Interprocess | |
143 | communications overview" | |
144 | */ | |
145 | class wxTCPConnection : public wxObject | |
146 | { | |
147 | public: | |
148 | //@{ | |
149 | /** | |
150 | Constructs a connection object. If no user-defined connection object is | |
151 | to be derived from wxTCPConnection, then the constructor should not be | |
152 | called directly, since the default connection object will be provided on | |
153 | requesting (or accepting) a connection. However, if the user defines his | |
154 | or her own derived connection object, the wxTCPServer::OnAcceptConnection | |
155 | and/or wxTCPClient::OnMakeConnection members should be replaced by | |
156 | functions which construct the new connection object. If the arguments of | |
157 | the wxTCPConnection constructor are void, then a default buffer is | |
158 | associated with the connection. Otherwise, the programmer must provide a | |
159 | a buffer and size of the buffer for the connection object to use in | |
160 | transactions. | |
161 | */ | |
162 | wxTCPConnection(); | |
7c913512 | 163 | wxTCPConnection(void* buffer, size_t size); |
23324ae1 FM |
164 | //@} |
165 | ||
166 | //@{ | |
167 | /** | |
168 | Called by the server application to advise the client of a change in | |
169 | the data associated with the given item. Causes the client | |
7c913512 | 170 | connection's OnAdvise() |
23324ae1 FM |
171 | member to be called. Returns @true if successful. |
172 | */ | |
173 | bool Advise(const wxString& item, const void* data, size_t size, | |
174 | wxIPCFormat format = wxIPC_PRIVATE); | |
7c913512 FM |
175 | bool Advise(const wxString& item, const char* data); |
176 | bool Advise(const wxString& item, const wchar_t* data); | |
177 | bool Advise(const wxString& item, const wxString data); | |
23324ae1 FM |
178 | //@} |
179 | ||
180 | /** | |
181 | Called by the client or server application to disconnect from the other | |
182 | program; it causes the OnDisconnect() message | |
183 | to be sent to the corresponding connection object in the other | |
184 | program. The default behaviour of @b OnDisconnect is to delete the | |
185 | connection, but the calling application must explicitly delete its | |
186 | side of the connection having called @b Disconnect. Returns @true if | |
187 | successful. | |
188 | */ | |
189 | bool Disconnect(); | |
190 | ||
191 | //@{ | |
192 | /** | |
193 | Called by the client application to execute a command on the server. Can | |
194 | also be used to transfer arbitrary data to the server (similar | |
195 | to Poke() in that respect). Causes the | |
196 | server connection's OnExecute() member to be | |
197 | called. Returns @true if successful. | |
198 | */ | |
199 | bool Execute(const void* data, size_t size, | |
200 | wxIPCFormat format = wxIPC_PRIVATE); | |
7c913512 FM |
201 | bool Execute(const char* data); |
202 | bool Execute(const wchar_t* data); | |
203 | bool Execute(const wxString data); | |
23324ae1 FM |
204 | //@} |
205 | ||
206 | /** | |
207 | Message sent to the client application when the server notifies it of a | |
208 | change in the data associated with the given item. | |
209 | */ | |
210 | virtual bool OnAdvise(const wxString& topic, | |
211 | const wxString& item, | |
212 | const void* data, | |
213 | size_t size, | |
214 | wxIPCFormat format); | |
215 | ||
216 | /** | |
217 | Message sent to the client or server application when the other | |
218 | application notifies it to delete the connection. Default behaviour is | |
219 | to delete the connection object. | |
220 | */ | |
221 | virtual bool OnDisconnect(); | |
222 | ||
223 | /** | |
224 | Message sent to the server application when the client notifies it to | |
225 | execute the given data. Note that there is no item associated with | |
226 | this message. | |
227 | */ | |
228 | virtual bool OnExecute(const wxString& topic, const void* data, | |
229 | size_t size, | |
230 | wxIPCFormat format); | |
231 | ||
232 | /** | |
233 | Message sent to the server application when the client notifies it to | |
234 | accept the given data. | |
235 | */ | |
236 | virtual bool OnPoke(const wxString& topic, const wxString& item, | |
237 | const void* data, | |
238 | size_t size, | |
239 | wxIPCFormat format); | |
240 | ||
241 | /** | |
242 | Message sent to the server application when the client | |
243 | calls Request(). The server | |
244 | should respond by returning a character string from @b OnRequest, | |
245 | or @NULL to indicate no data. | |
246 | */ | |
247 | virtual const void* OnRequest(const wxString& topic, | |
248 | const wxString& item, | |
4cc4bfaf | 249 | size_t* size, |
23324ae1 FM |
250 | wxIPCFormat format); |
251 | ||
252 | /** | |
253 | Message sent to the server application by the client, when the client | |
254 | wishes to start an 'advise loop' for the given topic and item. The | |
255 | server can refuse to participate by returning @false. | |
256 | */ | |
257 | virtual bool OnStartAdvise(const wxString& topic, | |
258 | const wxString& item); | |
259 | ||
260 | /** | |
261 | Message sent to the server application by the client, when the client | |
262 | wishes to stop an 'advise loop' for the given topic and item. The | |
263 | server can refuse to stop the advise loop by returning @false, although | |
264 | this doesn't have much meaning in practice. | |
265 | */ | |
266 | virtual bool OnStopAdvise(const wxString& topic, | |
267 | const wxString& item); | |
268 | ||
269 | //@{ | |
270 | /** | |
271 | Called by the client application to poke data into the server. Can be | |
272 | used to transfer arbitrary data to the server. Causes the server | |
273 | connection's OnPoke() member | |
274 | to be called. Returns @true if successful. | |
275 | */ | |
276 | bool Poke(const wxString& item, const void* data, size_t size, | |
277 | wxIPCFormat format = wxIPC_PRIVATE); | |
7c913512 FM |
278 | bool Poke(const wxString& item, const char* data); |
279 | bool Poke(const wxString& item, const wchar_t* data); | |
280 | bool Poke(const wxString& item, const wxString data); | |
23324ae1 FM |
281 | //@} |
282 | ||
283 | /** | |
284 | Called by the client application to request data from the server. Causes | |
285 | the server connection's OnRequest() member to be called. Returns a | |
286 | character string (actually a pointer to the connection's buffer) if | |
287 | successful, @NULL otherwise. | |
288 | */ | |
4cc4bfaf | 289 | const void* Request(const wxString& item, size_t* size, |
23324ae1 FM |
290 | wxIPCFormat format = wxIPC_TEXT); |
291 | ||
292 | /** | |
293 | Called by the client application to ask if an advise loop can be started | |
294 | with the server. Causes the server connection's OnStartAdvise() | |
295 | member to be called. Returns @true if the server okays it, @false | |
296 | otherwise. | |
297 | */ | |
298 | bool StartAdvise(const wxString& item); | |
299 | ||
300 | /** | |
301 | Called by the client application to ask if an advise loop can be | |
302 | stopped. Causes the server connection's OnStopAdvise() member | |
303 | to be called. Returns @true if the server okays it, @false otherwise. | |
304 | */ | |
305 | bool StopAdvise(const wxString& item); | |
306 | }; |