]>
Commit | Line | Data |
---|---|---|
e79848ac GL |
1 | \section{\class{wxSocketBase}}\label{wxsocketbase} |
2 | ||
3 | \wxheading{Derived from} | |
4 | ||
5 | \helpref{wxEvtHandler}{wxevthandler} | |
6 | ||
954b8ae6 JS |
7 | \wxheading{Include files} |
8 | ||
9 | <wx/socket.h> | |
10 | ||
407f3681 | 11 | \wxheading{wxSocket errors} |
aa6d9706 GL |
12 | |
13 | \twocolwidtha{7cm} | |
14 | \begin{twocollist}\itemsep=0pt | |
15 | \twocolitem{{\bf wxSOCKET\_NOERROR}}{No error happened.} | |
16 | \twocolitem{{\bf wxSOCKET\_INVOP}}{Invalid operation.} | |
17 | \twocolitem{{\bf wxSOCKET\_IOERR}}{Input/Output error.} | |
18 | \twocolitem{{\bf wxSOCKET\_INVADDR}}{Invalid address passed to wxSocket.} | |
19 | \twocolitem{{\bf wxSOCKET\_INVSOCK}}{Invalid socket (uninitialized).} | |
20 | \twocolitem{{\bf wxSOCKET\_NOHOST}}{No corresponding host.} | |
21 | \twocolitem{{\bf wxSOCKET\_INVPORT}}{Invalid port.} | |
cf85cb95 GRG |
22 | \twocolitem{{\bf wxSOCKET\_WOULDBLOCK}}{The socket is non-blocking and the operation would block.} |
23 | \twocolitem{{\bf wxSOCKET\_TIMEDOUT}}{The timeout for this operation expired.} | |
aa6d9706 | 24 | \twocolitem{{\bf wxSOCKET\_MEMERR}}{Memory exhausted.} |
a4625b8c | 25 | \end{twocollist} |
aa6d9706 | 26 | |
7e9a386e | 27 | \wxheading{wxSocket events} |
5a96d2f4 | 28 | |
aa6d9706 GL |
29 | \twocolwidtha{7cm} |
30 | \begin{twocollist}\itemsep=0pt | |
a4625b8c | 31 | \twocolitem{{\bf wxSOCKET\_INPUT}}{There is data available for reading.} |
aa6d9706 | 32 | \twocolitem{{\bf wxSOCKET\_OUTPUT}}{The socket is ready to be written to.} |
a4625b8c | 33 | \twocolitem{{\bf wxSOCKET\_CONNECTION}}{Incoming connection (server), or connection establishment (client).} |
cf85cb95 | 34 | \twocolitem{{\bf wxSOCKET\_LOST}}{The connection has been closed.} |
a4625b8c | 35 | \end{twocollist} |
5a96d2f4 | 36 | |
cf85cb95 GRG |
37 | A brief note on how to use these events: |
38 | ||
a4625b8c GRG |
39 | The {\bf wxSOCKET\_INPUT} event will be issued whenever there is data |
40 | available for reading. This will be the case if the input queue was | |
41 | empty and new data arrives, or if the application has read some data | |
42 | yet there is still more data available. This means that the application | |
43 | does not need to read all available data in response to a | |
44 | {\bf wxSOCKET\_INPUT} event, as more events will be produced as | |
45 | necessary. | |
46 | ||
47 | The {\bf wxSOCKET\_OUTPUT} event is issued when a socket is first | |
48 | connected with Connect or accepted with Accept. After that, new | |
49 | events will be generated only after an output operation fails | |
50 | with {\bf wxSOCKET\_WOULDBLOCK} and buffer space becomes available | |
51 | again. This means that the application should assume that it | |
52 | can write data to the socket until an {\bf wxSOCKET\_WOULDBLOCK} | |
53 | error occurs; after this, whenever the socket becomes writable | |
54 | again the application will be notified with another | |
55 | {\bf wxSOCKET\_OUTPUT} event. | |
56 | ||
57 | The {\bf wxSOCKET\_CONNECTION} event is issued when a delayed connection | |
58 | request completes succesfully (client) or when a new connection arrives | |
59 | at the incoming queue (server). | |
cf85cb95 GRG |
60 | |
61 | The {\bf wxSOCKET\_LOST} event is issued when a close indication is | |
62 | received for the socket. This means that the connection broke down or | |
a4625b8c GRG |
63 | that it was closed by the peer. Also, this event will be issued if |
64 | a delayed connection request fails. | |
cf85cb95 | 65 | |
e79848ac GL |
66 | % --------------------------------------------------------------------------- |
67 | % Event handling | |
68 | % --------------------------------------------------------------------------- | |
69 | \wxheading{Event handling} | |
70 | ||
71 | To process events from a socket, use the following event handler macro to direct | |
cf85cb95 | 72 | input to member functions that take a \helpref{wxSocketEvent}{wxsocketevent} argument. |
e79848ac | 73 | |
42ff6409 | 74 | \twocolwidtha{7cm}% |
e79848ac GL |
75 | \begin{twocollist}\itemsep=0pt |
76 | \twocolitem{{\bf EVT\_SOCKET(id, func)}}{A socket event occured.} | |
a4625b8c | 77 | \end{twocollist} |
e79848ac GL |
78 | |
79 | % --------------------------------------------------------------------------- | |
80 | % See also ... | |
81 | % --------------------------------------------------------------------------- | |
e79848ac GL |
82 | \wxheading{See also} |
83 | ||
407f3681 JS |
84 | \helpref{wxSocketEvent}{wxsocketevent}, |
85 | \helpref{wxSocketClient}{wxsocketclient}, | |
9f3430a6 | 86 | \helpref{wxSocketServer}{wxsocketserver} |
e79848ac GL |
87 | |
88 | % --------------------------------------------------------------------------- | |
89 | % Members | |
90 | % --------------------------------------------------------------------------- | |
e79848ac GL |
91 | \latexignore{\rtfignore{\wxheading{Members}}} |
92 | ||
93 | \membersection{wxSocketBase::wxSocketBase} | |
42ff6409 | 94 | |
e79848ac GL |
95 | \func{}{wxSocketBase}{\void} |
96 | ||
407f3681 | 97 | Default constructor. Don't use it; use \helpref{wxSocketClient}{wxsocketclient} |
e79848ac GL |
98 | or \helpref{wxSocketServer}{wxsocketserver}. |
99 | ||
100 | \membersection{wxSocketBase::\destruct{wxSocketBase}} | |
101 | ||
102 | \func{}{\destruct{wxSocketBase}}{\void} | |
103 | ||
104 | Destroys the wxSocketBase object. | |
105 | ||
106 | % --------------------------------------------------------------------------- | |
107 | % State functions | |
108 | % --------------------------------------------------------------------------- | |
109 | ||
5a96d2f4 GL |
110 | % |
111 | % SetFlags | |
112 | % | |
113 | ||
114 | \membersection{wxSocketBase::SetFlags}\label{wxsocketbasesetflags} | |
115 | ||
116 | \func{void}{SetFlags}{\param{wxSocketBase::wxSockFlags}{ flags}} | |
117 | ||
118 | \twocolwidtha{7cm} | |
119 | \begin{twocollist}\itemsep=0pt | |
a4625b8c GRG |
120 | \twocolitem{{\bf wxSOCKET\_NONE}}{Normal functionality.} |
121 | \twocolitem{{\bf wxSOCKET\_NOWAIT}}{Read/write as much data as possible and return immediately.} | |
122 | \twocolitem{{\bf wxSOCKET\_WAITALL}}{Wait for all required data to be read/written unless an error occurs.} | |
407f3681 | 123 | \twocolitem{{\bf wxSOCKET\_BLOCK}}{Block the GUI (do not wxYield) while reading/writing data.} |
5a96d2f4 GL |
124 | \end{twocollist} |
125 | ||
cf85cb95 GRG |
126 | A brief overview on how to use these flags follows. |
127 | ||
128 | If no flag is specified (this is the same as {\bf wxSOCKET\_NONE}), | |
129 | IO calls will return after some data has been read or written, even | |
130 | when the transfer might not be complete. This is the same as issuing | |
131 | exactly one blocking low-level call to recv() or send(). Note that | |
132 | blocking here refers to when the function returns, not to whether | |
133 | the GUI blocks during this time. | |
134 | ||
135 | If {\bf wxSOCKET\_NOWAIT} is specified, IO calls will return immediately. | |
136 | Read operations will retrieve only available data. Write operations will | |
137 | write as much data as possible, depending on how much space is available | |
138 | in the output buffer. This is the same as issuing exactly one nonblocking | |
139 | low-level call to recv() or send(). Note that nonblocking here refers to | |
140 | when the function returns, not to whether the GUI blocks during this time. | |
141 | ||
142 | If {\bf wxSOCKET\_WAITALL} is specified, IO calls won't return until ALL | |
143 | the data has been read or written (or until an error occurs), blocking if | |
144 | necessary, and issuing several low level calls if necessary. This is the | |
145 | same as having a loop which makes as many blocking low-level calls to | |
146 | recv() or send() as needed so as to transfer all the data. Note that | |
147 | "blocking" here refers to when the function returns, not to whether | |
148 | the GUI blocks during this time. | |
149 | ||
bf9b6711 GRG |
150 | The {\bf wxSOCKET\_BLOCK} flag controls whether the GUI blocks during |
151 | IO operations. If this flag is not used, then the application must take | |
cf85cb95 GRG |
152 | extra care to avoid unwanted reentrance. |
153 | ||
154 | So: | |
155 | ||
a4625b8c | 156 | {\bf wxSOCKET\_NONE} will try to read at least SOME data, no matter how much. |
407f3681 | 157 | |
cf85cb95 GRG |
158 | {\bf wxSOCKET\_NOWAIT} will always return immediately, even if it cannot |
159 | read or write ANY data. | |
407f3681 | 160 | |
cf85cb95 GRG |
161 | {\bf wxSOCKET\_WAITALL} will only return when it has read or written ALL |
162 | the data. | |
407f3681 | 163 | |
cf85cb95 | 164 | {\bf wxSOCKET\_BLOCK} has nothing to do with the previous flags and |
bf9b6711 | 165 | it controls whether the GUI blocks. |
cf85cb95 | 166 | |
5a96d2f4 GL |
167 | % |
168 | % SetNotify | |
169 | % | |
170 | \membersection{wxSocketBase::SetNotify}\label{wxsocketbasesetnotify} | |
171 | ||
cf85cb95 | 172 | \func{void}{SetNotify}{\param{wxSocketEventFlags}{ flags}} |
5a96d2f4 | 173 | |
cf85cb95 GRG |
174 | SetNotify specifies which socket events are to be sent to the event handler. |
175 | The {\it flags} parameter is a combination of flags ORed toghether. The | |
176 | following flags can be used: | |
aa6d9706 GL |
177 | |
178 | \twocolwidtha{7cm} | |
179 | \begin{twocollist}\itemsep=0pt | |
cf85cb95 GRG |
180 | \twocolitem{{\bf wxSOCKET\_INPUT\_FLAG}}{to receive wxSOCKET\_INPUT} |
181 | \twocolitem{{\bf wxSOCKET\_OUTPUT\_FLAG}}{to receive wxSOCKET\_OUTPUT} | |
182 | \twocolitem{{\bf wxSOCKET\_CONNECTION\_FLAG}}{to receive wxSOCKET\_CONNECTION} | |
183 | \twocolitem{{\bf wxSOCKET\_LOST\_FLAG}}{to receive wxSOCKET\_LOST} | |
a4625b8c | 184 | \end{twocollist} |
aa6d9706 GL |
185 | |
186 | For example: | |
407f3681 | 187 | |
aa6d9706 | 188 | \begin{verbatim} |
cf85cb95 | 189 | sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG); |
aa6d9706 | 190 | \end{verbatim} |
407f3681 | 191 | |
cf85cb95 GRG |
192 | In this example, the user will be notified about incoming socket data and |
193 | whenever the connection is closed. | |
aa6d9706 | 194 | |
7e9a386e | 195 | For more information on socket events see \helpref{wxSocket events}{wxsocketbase}. |
aa6d9706 GL |
196 | |
197 | % | |
198 | % SetTimeout | |
199 | % | |
bf9b6711 | 200 | \membersection{wxSocketBase::SetTimeout}\label{wxsocketbasesettimeout} |
7e9a386e | 201 | |
aa6d9706 GL |
202 | \func{void}{SetTimeout}{\param{int }{seconds}} |
203 | ||
cf85cb95 | 204 | This function sets the default socket timeout in seconds. This |
a4625b8c GRG |
205 | timeout applies to IO calls, and also to Wait() functions if you |
206 | don't specify a wait interval. If you never use SetTimeout(), the | |
cf85cb95 | 207 | default timeout will be 10 minutes. |
5a96d2f4 GL |
208 | |
209 | % | |
210 | % Notify | |
211 | % | |
d7cb14ce | 212 | \membersection{wxSocketBase::Notify}\label{wxsocketbasenotify} |
5a96d2f4 GL |
213 | |
214 | \func{void}{Notify}{\param{bool}{ notify}} | |
215 | ||
216 | Notify will enable (notify is TRUE) or disable (notify is FALSE) the propagation | |
217 | of socket events. | |
218 | ||
219 | % | |
220 | % Ok | |
221 | % | |
222 | ||
e79848ac GL |
223 | \membersection{wxSocketBase::Ok}\label{wxsocketbaseok} |
224 | ||
225 | \constfunc{bool}{Ok}{\void} | |
226 | ||
227 | Returns TRUE if the socket is initialized and ready and FALSE in other | |
228 | cases. | |
229 | ||
230 | \membersection{wxSocketBase::Error}\label{wxsocketbaseerror} | |
231 | ||
232 | \constfunc{bool}{Error}{\void} | |
233 | ||
cf85cb95 GRG |
234 | Returns TRUE if an error occured in the last IO operation. |
235 | ||
236 | The following operations update the Error() status: | |
237 | Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard. | |
e79848ac GL |
238 | |
239 | \membersection{wxSocketBase::IsConnected}\label{wxsocketbaseconnected} | |
240 | ||
241 | \constfunc{bool}{IsConnected}{\void} | |
242 | ||
243 | Returns TRUE if the socket is connected. | |
244 | ||
42ff6409 | 245 | \membersection{wxSocketBase::IsData}\label{wxsocketbaseisdata} |
e79848ac GL |
246 | |
247 | \constfunc{bool}{IsData}{\void} | |
248 | ||
cf85cb95 | 249 | Returns TRUE if there is data available to be read. |
e79848ac GL |
250 | |
251 | \membersection{wxSocketBase::IsDisconnected}\label{wxsocketbasedisconnected} | |
252 | ||
253 | \constfunc{bool}{IsDisconnected}{\void} | |
254 | ||
255 | Returns TRUE if the socket is disconnected. | |
256 | ||
257 | \membersection{wxSocketBase::IsNoWait}\label{wxsocketbasenowait} | |
258 | ||
259 | \constfunc{bool}{IsNoWait}{\void} | |
260 | ||
261 | Returns TRUE if the socket mustn't wait. | |
262 | ||
263 | \membersection{wxSocketBase::LastCount}\label{wxsocketbaselastcount} | |
264 | ||
aa6d9706 | 265 | \constfunc{wxUint32}{LastCount}{\void} |
e79848ac GL |
266 | |
267 | Returns the number of bytes read or written by the last IO call. | |
268 | ||
cf85cb95 GRG |
269 | The following operations update the LastCount() value: |
270 | Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard. | |
271 | ||
e79848ac GL |
272 | \membersection{wxSocketBase::LastError}\label{wxsocketbaselasterror} |
273 | ||
aa6d9706 | 274 | \constfunc{wxSocketError}{LastError}{\void} |
e79848ac | 275 | |
cf85cb95 GRG |
276 | Returns the last wxSocket error. See \helpref{wxSocket errors}{wxsocketbase}. |
277 | ||
278 | Please note that this function merely returns the last error code, | |
279 | but it should not be used to determine if an error has occured (this | |
a4625b8c | 280 | is because successful operations do not change the LastError value). |
cf85cb95 GRG |
281 | Use Error, instead of LastError, to determine if the last IO call |
282 | failed. If Error returns TRUE, use LastError to discover the | |
283 | cause of the error. | |
e79848ac GL |
284 | |
285 | % --------------------------------------------------------------------------- | |
286 | % IO calls | |
287 | % --------------------------------------------------------------------------- | |
e79848ac GL |
288 | % |
289 | % Peek | |
290 | % | |
e79848ac GL |
291 | \membersection{wxSocketBase::Peek}\label{wxsocketbasepeek} |
292 | ||
aa6d9706 | 293 | \func{wxSocketBase\&}{Peek}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac | 294 | |
a4625b8c GRG |
295 | This function peeks a buffer of {\it nbytes} bytes from the socket. |
296 | Peeking a buffer doesn't delete it from the socket input queue. | |
e79848ac | 297 | |
cf85cb95 GRG |
298 | Use LastCount to verify the number of bytes actually peeked. |
299 | ||
300 | Use Error to determine if the operation succeeded. | |
301 | ||
e79848ac GL |
302 | \wxheading{Parameters} |
303 | ||
304 | \docparam{buffer}{Buffer where to put peeked data.} | |
42ff6409 | 305 | |
e79848ac GL |
306 | \docparam{nbytes}{Number of bytes.} |
307 | ||
42ff6409 JS |
308 | \wxheading{Return value} |
309 | ||
e79848ac GL |
310 | Returns a reference to the current object. |
311 | ||
cf85cb95 GRG |
312 | \wxheading{Remark/Warning} |
313 | ||
314 | The exact behaviour of wxSocketBase::Peek() depends on the combination | |
315 | of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags} | |
316 | ||
e79848ac GL |
317 | \wxheading{See also} |
318 | ||
407f3681 JS |
319 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
320 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}, | |
321 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
cf85cb95 | 322 | \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags} |
e79848ac GL |
323 | |
324 | % | |
325 | % Read | |
326 | % | |
e79848ac GL |
327 | \membersection{wxSocketBase::Read}\label{wxsocketbaseread} |
328 | ||
aa6d9706 | 329 | \func{wxSocketBase\&}{Read}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac GL |
330 | |
331 | This function reads a buffer of {\it nbytes} bytes from the socket. | |
332 | ||
cf85cb95 GRG |
333 | Use LastCount to verify the number of bytes actually read. |
334 | ||
335 | Use Error to determine if the operation succeeded. | |
336 | ||
e79848ac GL |
337 | \wxheading{Parameters} |
338 | ||
339 | \docparam{buffer}{Buffer where to put read data.} | |
42ff6409 | 340 | |
e79848ac GL |
341 | \docparam{nbytes}{Number of bytes.} |
342 | ||
42ff6409 JS |
343 | \wxheading{Return value} |
344 | ||
e79848ac GL |
345 | Returns a reference to the current object. |
346 | ||
9f3430a6 GL |
347 | \wxheading{Remark/Warning} |
348 | ||
cf85cb95 | 349 | The exact behaviour of wxSocketBase::Read() depends on the combination |
407f3681 | 350 | of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}. |
9f3430a6 | 351 | |
e79848ac GL |
352 | \wxheading{See also} |
353 | ||
407f3681 JS |
354 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
355 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}, | |
356 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
cf85cb95 | 357 | \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags} |
42ff6409 | 358 | |
e79848ac | 359 | % |
5a96d2f4 | 360 | % Write |
e79848ac | 361 | % |
e79848ac GL |
362 | \membersection{wxSocketBase::Write}\label{wxsocketbasewrite} |
363 | ||
aa6d9706 | 364 | \func{wxSocketBase\&}{Write}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac | 365 | |
cf85cb95 | 366 | This function writes a buffer of {\it nbytes} bytes to the socket. |
e79848ac | 367 | |
cf85cb95 | 368 | Use LastCount to verify the number of bytes actually written. |
9f3430a6 | 369 | |
cf85cb95 | 370 | Use Error to determine if the operation succeeded. |
9f3430a6 | 371 | |
e79848ac GL |
372 | \wxheading{Parameters} |
373 | ||
cf85cb95 | 374 | \docparam{buffer}{Buffer with the data to be sent.} |
42ff6409 | 375 | |
e79848ac GL |
376 | \docparam{nbytes}{Number of bytes.} |
377 | ||
42ff6409 JS |
378 | \wxheading{Return value} |
379 | ||
e79848ac GL |
380 | Returns a reference to the current object. |
381 | ||
cf85cb95 GRG |
382 | \wxheading{Remark/Warning} |
383 | ||
384 | The exact behaviour of wxSocketBase::Write() depends on the combination | |
407f3681 | 385 | of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}. |
cf85cb95 | 386 | |
e79848ac GL |
387 | \wxheading{See also} |
388 | ||
407f3681 JS |
389 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
390 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}, | |
391 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
cf85cb95 | 392 | \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags} |
e79848ac GL |
393 | |
394 | % | |
395 | % WriteMsg | |
396 | % | |
e79848ac GL |
397 | \membersection{wxSocketBase::WriteMsg}\label{wxsocketbasewritemsg} |
398 | ||
aa6d9706 | 399 | \func{wxSocketBase\&}{WriteMsg}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac | 400 | |
cf85cb95 | 401 | This function writes a buffer of {\it nbytes} bytes from the socket, but it |
a4625b8c GRG |
402 | writes a short header before so that ReadMsg knows how much data should it |
403 | actually read. So, a buffer sent with WriteMsg {\bf must} be read with | |
404 | ReadMsg. This function always waits for the entire buffer to be sent, | |
405 | unless an error occurs. | |
cf85cb95 GRG |
406 | |
407 | Use LastCount to verify the number of bytes actually written. | |
408 | ||
409 | Use Error to determine if the operation succeeded. | |
e79848ac GL |
410 | |
411 | \wxheading{Parameters} | |
412 | ||
cf85cb95 | 413 | \docparam{buffer}{Buffer with the data to be sent.} |
42ff6409 | 414 | |
e79848ac GL |
415 | \docparam{nbytes}{Number of bytes.} |
416 | ||
42ff6409 JS |
417 | \wxheading{Return value} |
418 | ||
e79848ac GL |
419 | Returns a reference to the current object. |
420 | ||
cf85cb95 GRG |
421 | \wxheading{Remark/Warning} |
422 | ||
a4625b8c GRG |
423 | wxSocketBase::WriteMsg() will behave as if the {\bf wxSOCKET\_WAITALL} flag |
424 | was always set and it will always ignore the {\bf wxSOCKET\_NOWAIT} flag. | |
425 | The exact behaviour of WriteMsg depends on the {\bf wxSOCKET\_BLOCK} flag. | |
426 | For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}. | |
cf85cb95 | 427 | |
e79848ac GL |
428 | \wxheading{See also} |
429 | ||
407f3681 JS |
430 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
431 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}, | |
432 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
433 | \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}, | |
9f3430a6 | 434 | \helpref{wxSocketBase::ReadMsg}{wxsocketbasereadmsg} |
e79848ac GL |
435 | |
436 | % | |
437 | % ReadMsg | |
438 | % | |
e79848ac GL |
439 | \membersection{wxSocketBase::ReadMsg}\label{wxsocketbasereadmsg} |
440 | ||
aa6d9706 | 441 | \func{wxSocketBase\&}{ReadMsg}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac GL |
442 | |
443 | This function reads a buffer sent by WriteMsg on a socket. If the buffer passed | |
cf85cb95 GRG |
444 | to the function isn't big enough, the remaining bytes will be discarded. This |
445 | function always waits for the buffer to be entirely filled, unless an error occurs. | |
446 | ||
447 | Use LastCount to verify the number of bytes actually read. | |
448 | ||
449 | Use Error to determine if the operation succeeded. | |
e79848ac GL |
450 | |
451 | \wxheading{Parameters} | |
452 | ||
453 | \docparam{buffer}{Buffer where to put read data.} | |
42ff6409 | 454 | |
e79848ac GL |
455 | \docparam{nbytes}{Number of bytes allocated for the buffer.} |
456 | ||
42ff6409 JS |
457 | \wxheading{Return value} |
458 | ||
e79848ac GL |
459 | Returns a reference to the current object. |
460 | ||
cf85cb95 GRG |
461 | \wxheading{Remark/Warning} |
462 | ||
a4625b8c GRG |
463 | wxSocketBase::ReadMsg() will behave as if the {\bf wxSOCKET\_WAITALL} flag |
464 | was always set and it will always ignore the {\bf wxSOCKET\_NOWAIT} flag. | |
465 | The exact behaviour of ReadMsg depends on the {\bf wxSOCKET\_BLOCK} flag. | |
466 | For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}. | |
cf85cb95 | 467 | |
e79848ac GL |
468 | \wxheading{See also} |
469 | ||
407f3681 JS |
470 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
471 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}, | |
472 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
473 | \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}, | |
9f3430a6 | 474 | \helpref{wxSocketBase::WriteMsg}{wxsocketbasewritemsg} |
e79848ac GL |
475 | |
476 | % | |
477 | % Unread | |
478 | % | |
09eea162 | 479 | \membersection{wxSocketBase::Unread}\label{wxsocketbaseunread} |
e79848ac | 480 | |
aa6d9706 | 481 | \func{wxSocketBase\&}{Unread}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}} |
e79848ac | 482 | |
cf85cb95 GRG |
483 | This function unreads a buffer. That is, the data in the buffer is put back |
484 | in the incoming queue. This function is not affected by wxSocket flags. | |
485 | ||
486 | If you use LastCount, it will always return {\it nbytes}. | |
487 | ||
488 | If you use Error, it will always return FALSE. | |
e79848ac GL |
489 | |
490 | \wxheading{Parameters} | |
491 | ||
492 | \docparam{buffer}{Buffer to be unread.} | |
42ff6409 | 493 | |
e79848ac GL |
494 | \docparam{nbytes}{Number of bytes.} |
495 | ||
42ff6409 JS |
496 | \wxheading{Return value} |
497 | ||
e79848ac GL |
498 | Returns a reference to the current object. |
499 | ||
500 | \wxheading{See also} | |
501 | ||
407f3681 JS |
502 | \helpref{wxSocketBase::Error}{wxsocketbaseerror}, |
503 | \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}, | |
9f3430a6 | 504 | \helpref{wxSocketBase::LastError}{wxsocketbaselasterror} |
e79848ac GL |
505 | |
506 | % | |
507 | % Discard | |
508 | % | |
e79848ac GL |
509 | \membersection{wxSocketBase::Discard}\label{wxsocketbasediscard} |
510 | ||
511 | \func{wxSocketBase\&}{Discard}{\void} | |
512 | ||
513 | This function simply deletes all bytes in the incoming queue. This function | |
a4625b8c | 514 | always returns immediately and its operation is not affected by IO flags. |
cf85cb95 GRG |
515 | |
516 | Use LastCount to see the number of bytes discarded. | |
517 | ||
518 | If you use Error, it will always return FALSE. | |
e79848ac GL |
519 | |
520 | % --------------------------------------------------------------------------- | |
521 | % Wait functions | |
522 | % --------------------------------------------------------------------------- | |
523 | \membersection{wxSocketBase::Wait}\label{wxsocketbasewait} | |
42ff6409 | 524 | |
aa6d9706 | 525 | \func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}} |
e79848ac | 526 | |
cf85cb95 GRG |
527 | This function waits until one of the following conditions is true: there |
528 | is data available for reading; the output buffer is empty (you can send | |
529 | new data); the connection has been lost; an incoming connection arrived | |
530 | (only for servers); a connection request has completed (only for clients). | |
a4625b8c GRG |
531 | It is usually better to use the individual Wait functions to wait for the |
532 | required condition. | |
e79848ac GL |
533 | |
534 | \wxheading{Parameters} | |
535 | ||
cf85cb95 | 536 | \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.} |
42ff6409 | 537 | |
aa6d9706 | 538 | \docparam{millisecond}{Number of milliseconds to wait.} |
e79848ac | 539 | |
42ff6409 | 540 | \wxheading{Return value} |
e79848ac GL |
541 | |
542 | Returns TRUE if an event occured, FALSE if the timeout was reached. | |
543 | ||
544 | \wxheading{See also} | |
545 | ||
407f3681 JS |
546 | \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}, |
547 | \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}, | |
9f3430a6 | 548 | \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost} |
e79848ac GL |
549 | |
550 | % | |
551 | % WaitForRead | |
552 | % | |
e79848ac | 553 | \membersection{wxSocketBase::WaitForRead}\label{wxsocketbasewaitforread} |
42ff6409 | 554 | |
aa6d9706 | 555 | \func{bool}{WaitForRead}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}} |
e79848ac | 556 | |
cf85cb95 | 557 | This function waits until there is data available to be read. |
e79848ac GL |
558 | |
559 | \wxheading{Parameters} | |
560 | ||
cf85cb95 | 561 | \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.} |
42ff6409 | 562 | |
aa6d9706 | 563 | \docparam{millisecond}{Number of milliseconds to wait.} |
e79848ac | 564 | |
42ff6409 | 565 | \wxheading{Return value} |
e79848ac | 566 | |
cf85cb95 | 567 | Returns TRUE if there is data to be read, FALSE if the timeout was reached. |
e79848ac GL |
568 | |
569 | \wxheading{See also} | |
570 | ||
407f3681 JS |
571 | \helpref{wxSocketBase::Wait}{wxsocketbasewait}, |
572 | \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}, | |
9f3430a6 | 573 | \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost} |
e79848ac GL |
574 | |
575 | % | |
576 | % WaitForWrite | |
577 | % | |
e79848ac | 578 | \membersection{wxSocketBase::WaitForWrite}\label{wxsocketbasewaitforwrite} |
42ff6409 | 579 | |
aa6d9706 | 580 | \func{bool}{WaitForWrite}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}} |
e79848ac | 581 | |
cf85cb95 | 582 | This function waits until you can write to the socket. |
e79848ac GL |
583 | |
584 | \wxheading{Parameters} | |
585 | ||
cf85cb95 | 586 | \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.} |
42ff6409 | 587 | |
aa6d9706 | 588 | \docparam{millisecond}{Number of milliseconds to wait.} |
e79848ac | 589 | |
42ff6409 | 590 | \wxheading{Return value} |
e79848ac | 591 | |
cf85cb95 | 592 | Returns TRUE if you can write to the socket, FALSE if the timeout was reached. |
e79848ac GL |
593 | |
594 | \wxheading{See also} | |
595 | ||
407f3681 JS |
596 | \helpref{wxSocketBase::Wait}{wxsocketbasewait}, |
597 | \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}, | |
9f3430a6 | 598 | \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost} |
e79848ac GL |
599 | |
600 | % | |
601 | % WaitForLost | |
602 | % | |
e79848ac | 603 | \membersection{wxSocketBase::WaitForLost}\label{wxsocketbasewaitforlost} |
42ff6409 | 604 | |
aa6d9706 | 605 | \func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}} |
e79848ac | 606 | |
cf85cb95 GRG |
607 | This function waits until the connection is lost. This may happen if the |
608 | peer closes the connection or if the connection breaks. | |
e79848ac GL |
609 | |
610 | \wxheading{Parameters} | |
611 | ||
cf85cb95 | 612 | \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.} |
42ff6409 | 613 | |
aa6d9706 | 614 | \docparam{millisecond}{Number of milliseconds to wait.} |
e79848ac | 615 | |
42ff6409 | 616 | \wxheading{Return value} |
e79848ac | 617 | |
cf85cb95 | 618 | Returns TRUE if the connection was lost, FALSE if the timeout was reached. |
e79848ac GL |
619 | |
620 | \wxheading{See also} | |
621 | ||
407f3681 JS |
622 | \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}, |
623 | \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}, | |
9f3430a6 | 624 | \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost} |
42ff6409 | 625 | |
cf85cb95 GRG |
626 | % --------------------------------------------------------------------------- |
627 | % Socket state | |
628 | % --------------------------------------------------------------------------- | |
629 | ||
42ff6409 JS |
630 | % |
631 | % RestoreState | |
632 | % | |
633 | \membersection{wxSocketBase::RestoreState}\label{wxsocketbaserestorestate} | |
634 | ||
635 | \func{void}{RestoreState}{\void} | |
636 | ||
cf85cb95 GRG |
637 | This function restores the previous state of the socket, as saved |
638 | with SaveState. | |
639 | ||
640 | Calls to SaveState / RestoreState can be nested. | |
42ff6409 JS |
641 | |
642 | \wxheading{See also} | |
643 | ||
644 | \helpref{wxSocketBase::SaveState}{wxsocketbasesavestate} | |
e79848ac | 645 | |
e79848ac GL |
646 | % |
647 | % SaveState | |
648 | % | |
649 | \membersection{wxSocketBase::SaveState}\label{wxsocketbasesavestate} | |
42ff6409 | 650 | |
e79848ac GL |
651 | \func{void}{SaveState}{\void} |
652 | ||
653 | This function saves the current state of the socket object in a stack: | |
bf9b6711 | 654 | actually it saves all flags (those set with SetFlags, SetNotify, Notify) |
cf85cb95 GRG |
655 | and the state of the asynchronous callbacks (Callback, CallbackData). |
656 | ||
657 | Calls to SaveState / RestoreState can be nested. | |
e79848ac GL |
658 | |
659 | \wxheading{See also} | |
660 | ||
661 | \helpref{wxSocketBase::RestoreState}{wxsocketbaserestorestate} | |
aa6d9706 GL |
662 | |
663 | % | |
664 | % GetLocal | |
665 | % | |
666 | \membersection{wxSocketBase::GetLocal}{wxsocketbasegetlocal} | |
7e9a386e | 667 | |
605d715d | 668 | \constfunc{bool}{GetLocal}{\param{wxSockAddress\& }{addr\_man}} |
aa6d9706 GL |
669 | |
670 | This function returns the local address field of the socket. The local | |
671 | address field contains the complete local address of the socket (local | |
672 | address, local port, ...). | |
673 | ||
674 | \wxheading{Return value} | |
675 | ||
676 | It returns TRUE if no errors happened, FALSE otherwise. | |
677 | ||
678 | % | |
679 | % GetPeer | |
680 | % | |
681 | \membersection{wxSocketBase::GetPeer}{wxsocketbasegetlocal} | |
7e9a386e | 682 | |
605d715d | 683 | \constfunc{bool}{GetPeer}{\param{wxSockAddress\& }{addr\_man}} |
aa6d9706 GL |
684 | |
685 | This function returns the peer address field of the socket. The peer | |
686 | address field contains the complete peer host address of the socket | |
687 | (address, port, ...). | |
688 | ||
689 | \wxheading{Return value} | |
690 | ||
691 | It returns TRUE if no errors happened, FALSE otherwise. | |
e79848ac | 692 | |
e79848ac GL |
693 | % --------------------------------------------------------------------------- |
694 | % Socket callbacks | |
695 | % --------------------------------------------------------------------------- | |
42ff6409 | 696 | \membersection{wxSocketBase::SetEventHandler}\label{wxsocketbaseseteventhandler} |
e79848ac | 697 | |
e79848ac GL |
698 | \func{void}{SetEventHandler}{\param{wxEvtHandler\&}{ evt\_hdlr}, \param{int}{ id = -1}} |
699 | ||
cf85cb95 GRG |
700 | Sets an event handler to be called when a socket event occurs. The handler |
701 | will be called for those events for which notification is enabled with | |
702 | SetNotify and Notify. | |
703 | ||
a4625b8c GRG |
704 | You can also specify a callback function to be called when an event occurs. |
705 | See \helpref{Callback}{wxsocketbasecallback} and \helpref{CallbackData}{wxsocketbasecallbackdata}. | |
e79848ac GL |
706 | |
707 | \wxheading{Parameters} | |
708 | ||
709 | \docparam{evt\_hdlr}{Specifies the event handler you want to use.} | |
42ff6409 | 710 | |
e79848ac GL |
711 | \docparam{id}{The id of socket event.} |
712 | ||
713 | \wxheading{See also} | |
714 | ||
407f3681 JS |
715 | \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}, |
716 | \helpref{wxSocketBase::Notify}{wxsocketbasenotify}, | |
717 | \helpref{wxSocketEvent}{wxsocketevent}, | |
718 | \helpref{wxEvtHandler}{wxevthandler}, | |
719 | \helpref{wxSocketBase::Callback}{wxsocketbasecallback}, | |
cf85cb95 | 720 | \helpref{wxSocketBase::CallbackData}{wxsocketbasecallbackdata} |
aa6d9706 GL |
721 | |
722 | \membersection{wxSocketBase::Callback}\label{wxsocketbasecallback} | |
723 | ||
724 | \func{wxSocketBase::wxSockCbk}{Callback}{\param{wxSocketBase::wxSockCbk}{ callback}} | |
725 | ||
a4625b8c | 726 | You can setup a callback function to be called when an event occurs. The function |
cf85cb95 GRG |
727 | will be called only for those events for which notification has been enabled |
728 | with Notify and SetNotify. The prototype of the callback must be as follows: | |
729 | ||
aa6d9706 | 730 | \begin{verbatim} |
a4625b8c | 731 | void SocketCallback(wxSocketBase& sock, wxSocketNotify evt, char *cdata); |
aa6d9706 GL |
732 | \end{verbatim} |
733 | ||
cf85cb95 GRG |
734 | The first parameter is a reference to the socket object in which the event |
735 | occured. The second parameter tells you which event occured. (See \helpref{wxSocket events}{wxsocketbase}). | |
1fb3eae5 | 736 | The third parameter is the user data you specified using \helpref{CallbackData}{wxsocketbasecallbackdata}. |
aa6d9706 GL |
737 | |
738 | \wxheading{Return value} | |
739 | ||
cf85cb95 | 740 | A pointer to the previous callback. |
aa6d9706 GL |
741 | |
742 | \wxheading{See also} | |
743 | ||
407f3681 JS |
744 | \helpref{wxSocketBase::CallbackData}{wxsocketbasecallbackdata}, |
745 | \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}, | |
aa6d9706 GL |
746 | \helpref{wxSocketBase::Notify}{wxsocketbasenotify} |
747 | ||
cf85cb95 | 748 | \membersection{wxSocketBase::CallbackData}\label{wxsocketbasecallbackdata} |
aa6d9706 GL |
749 | |
750 | \func{char *}{CallbackData}{\param{char *}{cdata}} | |
751 | ||
a4625b8c GRG |
752 | This function sets the the user data which will be passed to a |
753 | callback function set via \helpref{Callback}{wxsocketbasecallback}. | |
aa6d9706 GL |
754 | |
755 | \wxheading{Return value} | |
756 | ||
cf85cb95 GRG |
757 | A pointer to the previous user data. |
758 | ||
407f3681 JS |
759 | \helpref{wxSocketBase::Callback}{wxsocketbasecallback}, |
760 | \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}, | |
cf85cb95 | 761 | \helpref{wxSocketBase::Notify}{wxsocketbasenotify} |
e79848ac GL |
762 | |
763 | % --------------------------------------------------------------------------- | |
764 | % CLASS wxSocketClient | |
765 | % --------------------------------------------------------------------------- | |
e79848ac GL |
766 | \section{\class{wxSocketClient}}\label{wxsocketclient} |
767 | ||
768 | \wxheading{Derived from} | |
769 | ||
770 | \helpref{wxSocketBase}{wxsocketbase} | |
771 | ||
954b8ae6 JS |
772 | \wxheading{Include files} |
773 | ||
774 | <wx/socket.h> | |
775 | ||
e79848ac GL |
776 | % --------------------------------------------------------------------------- |
777 | % Members | |
778 | % --------------------------------------------------------------------------- | |
e79848ac GL |
779 | % |
780 | % wxSocketClient | |
781 | % | |
e79848ac | 782 | \membersection{wxSocketClient::wxSocketClient} |
42ff6409 | 783 | |
e79848ac GL |
784 | \func{}{wxSocketClient}{\param{wxSockFlags}{ flags = wxSocketBase::NONE}} |
785 | ||
786 | Constructs a new wxSocketClient. | |
42ff6409 | 787 | |
e79848ac GL |
788 | \wxheading{Parameters} |
789 | ||
790 | \docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})} | |
791 | ||
792 | % | |
793 | % ~wxSocketClient | |
794 | % | |
e79848ac | 795 | \membersection{wxSocketClient::\destruct{wxSocketClient}} |
42ff6409 | 796 | |
e79848ac GL |
797 | \func{}{\destruct{wxSocketClient}}{\void} |
798 | ||
aed0ed3c | 799 | Destroys a wxSocketClient object. |
e79848ac GL |
800 | |
801 | % | |
802 | % Connect | |
803 | % | |
42ff6409 | 804 | \membersection{wxSocketClient::Connect}\label{wxsocketclientconnect} |
e79848ac | 805 | |
e79848ac GL |
806 | \func{bool}{Connect}{\param{wxSockAddress\&}{ address}, \param{bool}{ wait = TRUE}} |
807 | ||
cf85cb95 GRG |
808 | Connects to a server using the specified address. |
809 | ||
a4625b8c GRG |
810 | If {\it wait} is TRUE, Connect will wait until the connection completes |
811 | successfully, or until an event occurs. {\bf Warning !} This will block the GUI. | |
cf85cb95 GRG |
812 | |
813 | If {\it wait} is FALSE, Connect will try to establish the connection and | |
814 | return immediately, without blocking the GUI. When used this way, even if | |
815 | Connect returns FALSE, the connection request can be completed later. | |
a4625b8c GRG |
816 | To detect this, use WaitConnection, or catch {\bf wxSOCKET\_CONNECTION} |
817 | events (for successful establishment) and {\bf wxSOCKET\_LOST} events | |
818 | (for connection failure). | |
e79848ac GL |
819 | |
820 | \wxheading{Parameters} | |
821 | ||
822 | \docparam{address}{Address of the server.} | |
42ff6409 | 823 | |
a4625b8c | 824 | \docparam{wait}{If TRUE, waits for the connection to be ready.} |
e79848ac GL |
825 | |
826 | \wxheading{Return value} | |
827 | ||
828 | Returns TRUE if the connection is established and no error occurs. | |
829 | ||
cf85cb95 GRG |
830 | If {\it wait} was TRUE, and Connect returns FALSE, an error occured |
831 | and the connection failed. | |
832 | ||
833 | If {\it wait} was FALSE, and Connect returns FALSE, you should still | |
834 | be prepared to handle the completion of this connection request, either | |
a4625b8c GRG |
835 | with WaitOnConnect or by watching {\bf wxSOCKET\_CONNECTION} and |
836 | {\bf wxSOCKET\_LOST} events. | |
cf85cb95 | 837 | |
e79848ac GL |
838 | \wxheading{See also} |
839 | ||
407f3681 JS |
840 | \helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect}, |
841 | \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}, | |
cf85cb95 | 842 | \helpref{wxSocketBase::Notify}{wxsocketbasenotify} |
e79848ac GL |
843 | |
844 | % | |
845 | % WaitOnConnect | |
846 | % | |
42ff6409 | 847 | \membersection{wxSocketClient::WaitOnConnect}\label{wxsocketclientwaitonconnect} |
e79848ac | 848 | |
aa6d9706 | 849 | \func{bool}{WaitOnConnect}{\param{long}{ seconds = -1}, \param{long}{ milliseconds = 0}} |
e79848ac | 850 | |
cf85cb95 GRG |
851 | Wait until the connection is succesfully established or until it fails. |
852 | Use this function after a call to Connect with {\it wait} set to FALSE. | |
853 | ||
854 | \wxheading{Parameters} | |
855 | ||
856 | \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.} | |
857 | ||
858 | \docparam{millisecond}{Number of milliseconds to wait.} | |
859 | ||
860 | \wxheading{Return value} | |
861 | ||
862 | If the connection is succesfully established, it returns TRUE. | |
863 | ||
864 | If the timeout expires, or if the connection fails, it returns FALSE. | |
e79848ac GL |
865 | |
866 | \wxheading{See also} | |
867 | ||
cf85cb95 | 868 | \helpref{wxSocketClient::Connect}{wxsocketclientconnect} |
e79848ac GL |
869 | |
870 | % --------------------------------------------------------------------------- | |
42ff6409 | 871 | % CLASS: wxSocketEvent |
e79848ac | 872 | % --------------------------------------------------------------------------- |
42ff6409 | 873 | \section{\class{wxSocketEvent}}\label{wxsocketevent} |
e79848ac | 874 | |
42ff6409 | 875 | This event class contains information about socket events. |
e79848ac GL |
876 | |
877 | \wxheading{Derived from} | |
878 | ||
42ff6409 | 879 | \helpref{wxEvent}{wxevent} |
e79848ac | 880 | |
954b8ae6 JS |
881 | \wxheading{Include files} |
882 | ||
883 | <wx/socket.h> | |
884 | ||
42ff6409 | 885 | \wxheading{Event table macros} |
e79848ac | 886 | |
42ff6409 JS |
887 | To process a socket event, use these event handler macros to direct input to member |
888 | functions that take a wxSocketEvent argument. | |
e79848ac | 889 | |
42ff6409 JS |
890 | \twocolwidtha{7cm} |
891 | \begin{twocollist}\itemsep=0pt | |
892 | \twocolitem{{\bf EVT\_SOCKET(id, func)}}{Process a socket event, supplying the member function.} | |
893 | \end{twocollist}% | |
e79848ac GL |
894 | |
895 | \wxheading{See also} | |
896 | ||
407f3681 JS |
897 | \helpref{wxSocketBase}{wxsocketbase}, |
898 | \helpref{wxSocketClient}{wxsocketclient}, | |
42ff6409 | 899 | \helpref{wxSocketServer}{wxsocketserver} |
e79848ac | 900 | |
42ff6409 | 901 | \latexignore{\rtfignore{\wxheading{Members}}} |
e79848ac | 902 | |
42ff6409 | 903 | \membersection{wxSocketEvent::wxSocketEvent} |
e79848ac | 904 | |
42ff6409 | 905 | \func{}{wxSocketEvent}{\param{int}{ id = 0}} |
e79848ac | 906 | |
42ff6409 | 907 | Constructor. |
e79848ac | 908 | |
e5a2291a GRG |
909 | \membersection{wxSocketEvent::Socket}\label{wxsocketeventsocket} |
910 | ||
911 | \constfunc{wxSocketBase *}{Socket}{\void} | |
912 | ||
913 | Returns the socket object to which this event refers to. This makes | |
914 | it possible to use the same event handler for different sockets. | |
915 | ||
42ff6409 | 916 | \membersection{wxSocketEvent::SocketEvent}\label{wxsocketeventsocketevent} |
e79848ac | 917 | |
aa6d9706 | 918 | \constfunc{wxSocketNotify}{SocketEvent}{\void} |
e79848ac | 919 | |
42ff6409 | 920 | Returns the socket event type. |
e79848ac | 921 | |
42ff6409 JS |
922 | % --------------------------------------------------------------------------- |
923 | % CLASS: wxSocketServer | |
924 | % --------------------------------------------------------------------------- | |
925 | \section{\class{wxSocketServer}}\label{wxsocketserver} | |
926 | ||
927 | \wxheading{Derived from} | |
928 | ||
929 | \helpref{wxSocketBase}{wxsocketbase} | |
930 | ||
954b8ae6 JS |
931 | \wxheading{Include files} |
932 | ||
933 | <wx/socket.h> | |
934 | ||
42ff6409 JS |
935 | % --------------------------------------------------------------------------- |
936 | % Members | |
937 | % --------------------------------------------------------------------------- | |
938 | \latexignore{\rtfignore{\wxheading{Members}}} | |
939 | ||
940 | % | |
941 | % wxSocketServer | |
942 | % | |
943 | \membersection{wxSocketServer::wxSocketServer}\label{wxsocketserverconstr} | |
944 | ||
945 | \func{}{wxSocketServer}{\param{wxSockAddress\&}{ address}, \param{wxSockFlags}{ flags = wxSocketBase::NONE}} | |
946 | ||
947 | Constructs a new wxSocketServer. | |
948 | ||
42ff6409 JS |
949 | \wxheading{Parameters} |
950 | ||
951 | \docparam{address}{Specifies the local address for the server (e.g. port number).} | |
952 | ||
953 | \docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})} | |
954 | ||
955 | % | |
956 | % ~wxSocketServer | |
957 | % | |
958 | \membersection{wxSocketServer::\destruct{wxSocketServer}} | |
959 | ||
960 | \func{}{\destruct{wxSocketServer}}{\void} | |
961 | ||
cf85cb95 | 962 | Destroys a wxSocketServer object (it doesn't close the accepted connections). |
42ff6409 JS |
963 | |
964 | % | |
965 | % Accept | |
966 | % | |
1fb3eae5 | 967 | \membersection{wxSocketServer::Accept}\label{wxsocketserveraccept} |
42ff6409 | 968 | |
cf85cb95 GRG |
969 | \func{wxSocketBase *}{Accept}{\param{bool}{ wait = TRUE}} |
970 | ||
971 | Creates a new object wxSocketBase and accepts an incoming connection. | |
42ff6409 | 972 | |
cf85cb95 GRG |
973 | If {\it wait} is TRUE and there are no pending connections to be |
974 | accepted, it will wait for the next incoming connection to arrive. | |
975 | {\bf Warning !} This will block the GUI. | |
976 | ||
977 | If {\it wait} is FALSE, it will try to accept a pending connection | |
978 | if there is one, but it will always return immediately without | |
979 | blocking the GUI. If you want to use Accept in this way, you can | |
980 | either check for incoming connections with WaitForAccept or watch | |
a4625b8c GRG |
981 | {\bf wxSOCKET\_CONNECTION} events, then call Accept once you know |
982 | that there is an incoming connection waiting to be accepted. | |
42ff6409 JS |
983 | |
984 | \wxheading{Return value} | |
985 | ||
cf85cb95 GRG |
986 | Returns an opened socket connection, or NULL if an error occured or |
987 | if the {\it wait} parameter was FALSE and there were no pending | |
988 | connections. | |
42ff6409 JS |
989 | |
990 | \wxheading{See also} | |
991 | ||
1fb3eae5 | 992 | \helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept}, |
407f3681 JS |
993 | \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}, |
994 | \helpref{wxSocketBase::Notify}{wxsocketbasenotify}, | |
42ff6409 JS |
995 | \helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith} |
996 | ||
997 | % | |
998 | % AcceptWith | |
999 | % | |
1000 | \membersection{wxSocketServer::AcceptWith}\label{wxsocketserveracceptwith} | |
1001 | ||
cf85cb95 | 1002 | \func{bool}{AcceptWith}{\param{wxSocketBase\&}{ socket}, \param{bool}{ wait = TRUE}} |
42ff6409 JS |
1003 | |
1004 | Accept an incoming connection using the specified socket object. | |
42ff6409 JS |
1005 | |
1006 | \wxheading{Parameters} | |
1007 | ||
1008 | \docparam{socket}{Socket to be initialized} | |
1009 | ||
1010 | \wxheading{Return value} | |
1011 | ||
cf85cb95 GRG |
1012 | Returns TRUE on success, or FALSE if an error occured or if the |
1013 | {\it wait} parameter was FALSE and there were no pending | |
1014 | connections. | |
1015 | ||
1fb3eae5 | 1016 | \helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept}, |
407f3681 JS |
1017 | \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}, |
1018 | \helpref{wxSocketBase::Notify}{wxsocketbasenotify}, | |
bf9b6711 | 1019 | \helpref{wxSocketServer::Accept}{wxsocketserveraccept} for a detailed explanation |
cf85cb95 GRG |
1020 | |
1021 | % | |
1022 | % WaitForAccept | |
1023 | % | |
1024 | \membersection{wxSocketServer::WaitForAccept}\label{wxsocketserverwaitforaccept} | |
1025 | ||
1026 | \func{bool}{WaitForAccept}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}} | |
1027 | ||
1028 | This function waits for an incoming connection. Use it if you want to call | |
1029 | Accept or AcceptWith with {\it wait} set to FALSE, to detect when an incoming | |
1030 | connection is waiting to be accepted. | |
1031 | ||
1032 | \wxheading{Parameters} | |
1033 | ||
1034 | \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.} | |
1035 | ||
1036 | \docparam{millisecond}{Number of milliseconds to wait.} | |
1037 | ||
1038 | \wxheading{Return value} | |
1039 | ||
1040 | Returns TRUE if an incoming connection arrived, FALSE if the timeout expired. | |
1041 | ||
1042 | \wxheading{See also} | |
1043 | ||
407f3681 | 1044 | \helpref{wxSocketServer::Accept}{wxsocketserveraccept}, |
cf85cb95 GRG |
1045 | \helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith} |
1046 |