]>
git.saurik.com Git - wxWidgets.git/blob - interface/sckipc.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxTCPServer
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
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
17 A DDE-based implementation for Windows is available using wxDDEServer.
22 @see wxTCPClient, wxTCPConnection, @ref overview_ipcoverview "IPC overview"
24 class wxTCPServer
: public wxObject
28 Constructs a server object.
33 Registers the server using the given service name. Under Unix, the
34 string must contain an integer id which is used as an Internet port
35 number. @false is returned if the call failed (for example, the port
36 number is already in use).
38 bool Create(const wxString
& service
);
41 When a client calls @b MakeConnection, the server receives the
42 message and this member is called. The application should derive a
43 member to intercept this message and return a connection object of
44 either the standard wxTCPConnection type, or of a user-derived type. If the
45 topic is "STDIO'', the application may wish to refuse the connection.
46 Under Unix, when a server is created the OnAcceptConnection message is
47 always sent for standard input and output.
49 virtual wxConnectionBase
* OnAcceptConnection(const wxString
& topic
);
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
62 A DDE-based implementation for Windows is available using wxDDEClient.
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.
74 @see wxTCPServer, wxTCPConnection, @ref overview_ipcoverview "Interprocess
75 communications overview"
77 class wxTCPClient
: public wxObject
81 Constructs a client object.
86 Tries to make a connection with a server specified by the host
87 (a machine name under Unix), service name (must
88 contain an integer port number under Unix), and a topic string. If the
89 server allows a connection, a wxTCPConnection object will be returned.
90 The type of wxTCPConnection returned can be altered by overriding
91 the OnMakeConnection() member to return your own
92 derived connection object.
94 wxConnectionBase
* MakeConnection(const wxString
& host
,
95 const wxString
& service
,
96 const wxString
& topic
);
99 The type of wxTCPConnection returned from a MakeConnection() call can
100 be altered by deriving the @b OnMakeConnection member to return your
101 own derived connection object. By default, a wxTCPConnection
103 The advantage of deriving your own connection class is that it will
104 enable you to intercept messages initiated by the server, such
105 as wxTCPConnection::OnAdvise. You may also want to
106 store application-specific data in instances of the new class.
108 wxConnectionBase
* OnMakeConnection();
111 Returns @true if this is a valid host name, @false otherwise.
113 bool ValidHost(const wxString
& host
);
119 @class wxTCPConnection
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
126 A DDE-based implementation for Windows is available using wxDDEConnection.
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
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.
141 @see wxTCPClient, wxTCPServer, @ref overview_ipcoverview "Interprocess
142 communications overview"
144 class wxTCPConnection
: public wxObject
149 Constructs a connection object. If no user-defined connection object is
150 to be derived from wxTCPConnection, then the constructor should not be
151 called directly, since the default connection object will be provided on
152 requesting (or accepting) a connection. However, if the user defines his
153 or her own derived connection object, the wxTCPServer::OnAcceptConnection
154 and/or wxTCPClient::OnMakeConnection members should be replaced by
155 functions which construct the new connection object. If the arguments of
156 the wxTCPConnection constructor are void, then a default buffer is
157 associated with the connection. Otherwise, the programmer must provide a
158 a buffer and size of the buffer for the connection object to use in
162 wxTCPConnection(void* buffer
, size_t size
);
167 Called by the server application to advise the client of a change in
168 the data associated with the given item. Causes the client
169 connection's OnAdvise()
170 member to be called. Returns @true if successful.
172 bool Advise(const wxString
& item
, const void* data
, size_t size
,
173 wxIPCFormat format
= wxIPC_PRIVATE
);
174 bool Advise(const wxString
& item
, const char* data
);
175 bool Advise(const wxString
& item
, const wchar_t* data
);
176 bool Advise(const wxString
& item
, const wxString data
);
180 Called by the client or server application to disconnect from the other
181 program; it causes the OnDisconnect() message
182 to be sent to the corresponding connection object in the other
183 program. The default behaviour of @b OnDisconnect is to delete the
184 connection, but the calling application must explicitly delete its
185 side of the connection having called @b Disconnect. Returns @true if
192 Called by the client application to execute a command on the server. Can
193 also be used to transfer arbitrary data to the server (similar
194 to Poke() in that respect). Causes the
195 server connection's OnExecute() member to be
196 called. Returns @true if successful.
198 bool Execute(const void* data
, size_t size
,
199 wxIPCFormat format
= wxIPC_PRIVATE
);
200 bool Execute(const char* data
);
201 bool Execute(const wchar_t* data
);
202 bool Execute(const wxString data
);
206 Message sent to the client application when the server notifies it of a
207 change in the data associated with the given item.
209 virtual bool OnAdvise(const wxString
& topic
,
210 const wxString
& item
,
216 Message sent to the client or server application when the other
217 application notifies it to delete the connection. Default behaviour is
218 to delete the connection object.
220 virtual bool OnDisconnect();
223 Message sent to the server application when the client notifies it to
224 execute the given data. Note that there is no item associated with
227 virtual bool OnExecute(const wxString
& topic
, const void* data
,
232 Message sent to the server application when the client notifies it to
233 accept the given data.
235 virtual bool OnPoke(const wxString
& topic
, const wxString
& item
,
241 Message sent to the server application when the client
242 calls Request(). The server
243 should respond by returning a character string from @b OnRequest,
244 or @NULL to indicate no data.
246 virtual const void* OnRequest(const wxString
& topic
,
247 const wxString
& item
,
252 Message sent to the server application by the client, when the client
253 wishes to start an 'advise loop' for the given topic and item. The
254 server can refuse to participate by returning @false.
256 virtual bool OnStartAdvise(const wxString
& topic
,
257 const wxString
& item
);
260 Message sent to the server application by the client, when the client
261 wishes to stop an 'advise loop' for the given topic and item. The
262 server can refuse to stop the advise loop by returning @false, although
263 this doesn't have much meaning in practice.
265 virtual bool OnStopAdvise(const wxString
& topic
,
266 const wxString
& item
);
270 Called by the client application to poke data into the server. Can be
271 used to transfer arbitrary data to the server. Causes the server
272 connection's OnPoke() member
273 to be called. Returns @true if successful.
275 bool Poke(const wxString
& item
, const void* data
, size_t size
,
276 wxIPCFormat format
= wxIPC_PRIVATE
);
277 bool Poke(const wxString
& item
, const char* data
);
278 bool Poke(const wxString
& item
, const wchar_t* data
);
279 bool Poke(const wxString
& item
, const wxString data
);
283 Called by the client application to request data from the server. Causes
284 the server connection's OnRequest() member to be called. Returns a
285 character string (actually a pointer to the connection's buffer) if
286 successful, @NULL otherwise.
288 const void* Request(const wxString
& item
, size_t* size
,
289 wxIPCFormat format
= wxIPC_TEXT
);
292 Called by the client application to ask if an advise loop can be started
293 with the server. Causes the server connection's OnStartAdvise()
294 member to be called. Returns @true if the server okays it, @false
297 bool StartAdvise(const wxString
& item
);
300 Called by the client application to ask if an advise loop can be
301 stopped. Causes the server connection's OnStopAdvise() member
302 to be called. Returns @true if the server okays it, @false otherwise.
304 bool StopAdvise(const wxString
& item
);