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