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