]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/socket.tex
Updated some bits in socket docs.
[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}}{There is data available for reading.}
32 \twocolitem{{\bf wxSOCKET\_OUTPUT}}{The socket is ready to be written to.}
33 \twocolitem{{\bf wxSOCKET\_CONNECTION}}{Incoming connection (server), or connection establishment (client).}
34 \twocolitem{{\bf wxSOCKET\_LOST}}{The connection has been closed.}
35 \end{twocollist}
36
37 A brief note on how to use these events:
38
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).
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
63 that it was closed by the peer. Also, this event will be issued if
64 a delayed connection request fails.
65
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
72 input to member functions that take a \helpref{wxSocketEvent}{wxsocketevent} argument.
73
74 \twocolwidtha{7cm}%
75 \begin{twocollist}\itemsep=0pt
76 \twocolitem{{\bf EVT\_SOCKET(id, func)}}{A socket event occured.}
77 \end{twocollist}
78
79 % ---------------------------------------------------------------------------
80 % See also ...
81 % ---------------------------------------------------------------------------
82 \wxheading{See also}
83
84 \helpref{wxSocketEvent}{wxsocketevent},
85 \helpref{wxSocketClient}{wxsocketclient},
86 \helpref{wxSocketServer}{wxsocketserver}
87
88 % ---------------------------------------------------------------------------
89 % Members
90 % ---------------------------------------------------------------------------
91 \latexignore{\rtfignore{\wxheading{Members}}}
92
93 \membersection{wxSocketBase::wxSocketBase}
94
95 \func{}{wxSocketBase}{\void}
96
97 Default constructor. Don't use it; use \helpref{wxSocketClient}{wxsocketclient}
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
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
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.}
123 \twocolitem{{\bf wxSOCKET\_BLOCK}}{Block the GUI (do not wxYield) while reading/writing data.}
124 \end{twocollist}
125
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
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
152 extra care to avoid unwanted reentrance.
153
154 So:
155
156 {\bf wxSOCKET\_NONE} will try to read at least SOME data, no matter how much.
157
158 {\bf wxSOCKET\_NOWAIT} will always return immediately, even if it cannot
159 read or write ANY data.
160
161 {\bf wxSOCKET\_WAITALL} will only return when it has read or written ALL
162 the data.
163
164 {\bf wxSOCKET\_BLOCK} has nothing to do with the previous flags and
165 it controls whether the GUI blocks.
166
167 %
168 % SetNotify
169 %
170 \membersection{wxSocketBase::SetNotify}\label{wxsocketbasesetnotify}
171
172 \func{void}{SetNotify}{\param{wxSocketEventFlags}{ flags}}
173
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:
177
178 \twocolwidtha{7cm}
179 \begin{twocollist}\itemsep=0pt
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}
184 \end{twocollist}
185
186 For example:
187
188 \begin{verbatim}
189 sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
190 \end{verbatim}
191
192 In this example, the user will be notified about incoming socket data and
193 whenever the connection is closed.
194
195 For more information on socket events see \helpref{wxSocket events}{wxsocketbase}.
196
197 %
198 % SetTimeout
199 %
200 \membersection{wxSocketBase::SetTimeout}\label{wxsocketbasesettimeout}
201
202 \func{void}{SetTimeout}{\param{int }{seconds}}
203
204 This function sets the default socket timeout in seconds. This
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
207 default timeout will be 10 minutes.
208
209 %
210 % Notify
211 %
212 \membersection{wxSocketBase::Notify}\label{wxsocketbasenotify}
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
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
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.
238
239 \membersection{wxSocketBase::IsConnected}\label{wxsocketbaseconnected}
240
241 \constfunc{bool}{IsConnected}{\void}
242
243 Returns TRUE if the socket is connected.
244
245 \membersection{wxSocketBase::IsData}\label{wxsocketbaseisdata}
246
247 \constfunc{bool}{IsData}{\void}
248
249 Returns TRUE if there is data available to be read.
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
265 \constfunc{wxUint32}{LastCount}{\void}
266
267 Returns the number of bytes read or written by the last IO call.
268
269 The following operations update the LastCount() value:
270 Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
271
272 \membersection{wxSocketBase::LastError}\label{wxsocketbaselasterror}
273
274 \constfunc{wxSocketError}{LastError}{\void}
275
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
280 is because successful operations do not change the LastError value).
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.
284
285 % ---------------------------------------------------------------------------
286 % IO calls
287 % ---------------------------------------------------------------------------
288 %
289 % Peek
290 %
291 \membersection{wxSocketBase::Peek}\label{wxsocketbasepeek}
292
293 \func{wxSocketBase\&}{Peek}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
294
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.
297
298 Use LastCount to verify the number of bytes actually peeked.
299
300 Use Error to determine if the operation succeeded.
301
302 \wxheading{Parameters}
303
304 \docparam{buffer}{Buffer where to put peeked data.}
305
306 \docparam{nbytes}{Number of bytes.}
307
308 \wxheading{Return value}
309
310 Returns a reference to the current object.
311
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
317 \wxheading{See also}
318
319 \helpref{wxSocketBase::Error}{wxsocketbaseerror},
320 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
321 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
322 \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
323
324 %
325 % Read
326 %
327 \membersection{wxSocketBase::Read}\label{wxsocketbaseread}
328
329 \func{wxSocketBase\&}{Read}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
330
331 This function reads a buffer of {\it nbytes} bytes from the socket.
332
333 Use LastCount to verify the number of bytes actually read.
334
335 Use Error to determine if the operation succeeded.
336
337 \wxheading{Parameters}
338
339 \docparam{buffer}{Buffer where to put read data.}
340
341 \docparam{nbytes}{Number of bytes.}
342
343 \wxheading{Return value}
344
345 Returns a reference to the current object.
346
347 \wxheading{Remark/Warning}
348
349 The exact behaviour of wxSocketBase::Read() depends on the combination
350 of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}.
351
352 \wxheading{See also}
353
354 \helpref{wxSocketBase::Error}{wxsocketbaseerror},
355 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
356 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
357 \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
358
359 %
360 % Write
361 %
362 \membersection{wxSocketBase::Write}\label{wxsocketbasewrite}
363
364 \func{wxSocketBase\&}{Write}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
365
366 This function writes a buffer of {\it nbytes} bytes to the socket.
367
368 Use LastCount to verify the number of bytes actually written.
369
370 Use Error to determine if the operation succeeded.
371
372 \wxheading{Parameters}
373
374 \docparam{buffer}{Buffer with the data to be sent.}
375
376 \docparam{nbytes}{Number of bytes.}
377
378 \wxheading{Return value}
379
380 Returns a reference to the current object.
381
382 \wxheading{Remark/Warning}
383
384 The exact behaviour of wxSocketBase::Write() depends on the combination
385 of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}.
386
387 \wxheading{See also}
388
389 \helpref{wxSocketBase::Error}{wxsocketbaseerror},
390 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
391 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
392 \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
393
394 %
395 % WriteMsg
396 %
397 \membersection{wxSocketBase::WriteMsg}\label{wxsocketbasewritemsg}
398
399 \func{wxSocketBase\&}{WriteMsg}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
400
401 This function writes a buffer of {\it nbytes} bytes from the socket, but it
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.
406
407 Use LastCount to verify the number of bytes actually written.
408
409 Use Error to determine if the operation succeeded.
410
411 \wxheading{Parameters}
412
413 \docparam{buffer}{Buffer with the data to be sent.}
414
415 \docparam{nbytes}{Number of bytes.}
416
417 \wxheading{Return value}
418
419 Returns a reference to the current object.
420
421 \wxheading{Remark/Warning}
422
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}.
427
428 \wxheading{See also}
429
430 \helpref{wxSocketBase::Error}{wxsocketbaseerror},
431 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
432 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
433 \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags},
434 \helpref{wxSocketBase::ReadMsg}{wxsocketbasereadmsg}
435
436 %
437 % ReadMsg
438 %
439 \membersection{wxSocketBase::ReadMsg}\label{wxsocketbasereadmsg}
440
441 \func{wxSocketBase\&}{ReadMsg}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
442
443 This function reads a buffer sent by WriteMsg on a socket. If the buffer passed
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.
450
451 \wxheading{Parameters}
452
453 \docparam{buffer}{Buffer where to put read data.}
454
455 \docparam{nbytes}{Number of bytes allocated for the buffer.}
456
457 \wxheading{Return value}
458
459 Returns a reference to the current object.
460
461 \wxheading{Remark/Warning}
462
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}.
467
468 \wxheading{See also}
469
470 \helpref{wxSocketBase::Error}{wxsocketbaseerror},
471 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
472 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
473 \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags},
474 \helpref{wxSocketBase::WriteMsg}{wxsocketbasewritemsg}
475
476 %
477 % Unread
478 %
479 \membersection{wxSocketBase::Unread}\label{wxsocketbaseunread}
480
481 \func{wxSocketBase\&}{Unread}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
482
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.
489
490 \wxheading{Parameters}
491
492 \docparam{buffer}{Buffer to be unread.}
493
494 \docparam{nbytes}{Number of bytes.}
495
496 \wxheading{Return value}
497
498 Returns a reference to the current object.
499
500 \wxheading{See also}
501
502 \helpref{wxSocketBase::Error}{wxsocketbaseerror},
503 \helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
504 \helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
505
506 %
507 % Discard
508 %
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
514 always returns immediately and its operation is not affected by IO flags.
515
516 Use LastCount to see the number of bytes discarded.
517
518 If you use Error, it will always return FALSE.
519
520 % ---------------------------------------------------------------------------
521 % Wait functions
522 % ---------------------------------------------------------------------------
523 \membersection{wxSocketBase::Wait}\label{wxsocketbasewait}
524
525 \func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
526
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).
531 It is usually better to use the individual Wait functions to wait for the
532 required condition.
533
534 \wxheading{Parameters}
535
536 \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
537
538 \docparam{millisecond}{Number of milliseconds to wait.}
539
540 \wxheading{Return value}
541
542 Returns TRUE if an event occured, FALSE if the timeout was reached.
543
544 \wxheading{See also}
545
546 \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
547 \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
548 \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
549
550 %
551 % WaitForRead
552 %
553 \membersection{wxSocketBase::WaitForRead}\label{wxsocketbasewaitforread}
554
555 \func{bool}{WaitForRead}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
556
557 This function waits until there is data available to be read.
558
559 \wxheading{Parameters}
560
561 \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
562
563 \docparam{millisecond}{Number of milliseconds to wait.}
564
565 \wxheading{Return value}
566
567 Returns TRUE if there is data to be read, FALSE if the timeout was reached.
568
569 \wxheading{See also}
570
571 \helpref{wxSocketBase::Wait}{wxsocketbasewait},
572 \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
573 \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
574
575 %
576 % WaitForWrite
577 %
578 \membersection{wxSocketBase::WaitForWrite}\label{wxsocketbasewaitforwrite}
579
580 \func{bool}{WaitForWrite}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
581
582 This function waits until you can write to the socket.
583
584 \wxheading{Parameters}
585
586 \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
587
588 \docparam{millisecond}{Number of milliseconds to wait.}
589
590 \wxheading{Return value}
591
592 Returns TRUE if you can write to the socket, FALSE if the timeout was reached.
593
594 \wxheading{See also}
595
596 \helpref{wxSocketBase::Wait}{wxsocketbasewait},
597 \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
598 \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
599
600 %
601 % WaitForLost
602 %
603 \membersection{wxSocketBase::WaitForLost}\label{wxsocketbasewaitforlost}
604
605 \func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
606
607 This function waits until the connection is lost. This may happen if the
608 peer closes the connection or if the connection breaks.
609
610 \wxheading{Parameters}
611
612 \docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
613
614 \docparam{millisecond}{Number of milliseconds to wait.}
615
616 \wxheading{Return value}
617
618 Returns TRUE if the connection was lost, FALSE if the timeout was reached.
619
620 \wxheading{See also}
621
622 \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
623 \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
624 \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
625
626 % ---------------------------------------------------------------------------
627 % Socket state
628 % ---------------------------------------------------------------------------
629
630 %
631 % RestoreState
632 %
633 \membersection{wxSocketBase::RestoreState}\label{wxsocketbaserestorestate}
634
635 \func{void}{RestoreState}{\void}
636
637 This function restores the previous state of the socket, as saved
638 with SaveState.
639
640 Calls to SaveState / RestoreState can be nested.
641
642 \wxheading{See also}
643
644 \helpref{wxSocketBase::SaveState}{wxsocketbasesavestate}
645
646 %
647 % SaveState
648 %
649 \membersection{wxSocketBase::SaveState}\label{wxsocketbasesavestate}
650
651 \func{void}{SaveState}{\void}
652
653 This function saves the current state of the socket object in a stack:
654 actually it saves all flags (those set with SetFlags, SetNotify, Notify)
655 and the state of the asynchronous callbacks (Callback, CallbackData).
656
657 Calls to SaveState / RestoreState can be nested.
658
659 \wxheading{See also}
660
661 \helpref{wxSocketBase::RestoreState}{wxsocketbaserestorestate}
662
663 %
664 % GetLocal
665 %
666 \membersection{wxSocketBase::GetLocal}{wxsocketbasegetlocal}
667
668 \constfunc{bool}{GetLocal}{\param{wxSockAddress\& }{addr\_man}}
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}
682
683 \constfunc{bool}{GetPeer}{\param{wxSockAddress\& }{addr\_man}}
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.
692
693 % ---------------------------------------------------------------------------
694 % Socket callbacks
695 % ---------------------------------------------------------------------------
696 \membersection{wxSocketBase::SetEventHandler}\label{wxsocketbaseseteventhandler}
697
698 \func{void}{SetEventHandler}{\param{wxEvtHandler\&}{ evt\_hdlr}, \param{int}{ id = -1}}
699
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
704 You can also specify a callback function to be called when an event occurs.
705 See \helpref{Callback}{wxsocketbasecallback} and \helpref{CallbackData}{wxsocketbasecallbackdata}.
706
707 \wxheading{Parameters}
708
709 \docparam{evt\_hdlr}{Specifies the event handler you want to use.}
710
711 \docparam{id}{The id of socket event.}
712
713 \wxheading{See also}
714
715 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
716 \helpref{wxSocketBase::Notify}{wxsocketbasenotify},
717 \helpref{wxSocketEvent}{wxsocketevent},
718 \helpref{wxEvtHandler}{wxevthandler},
719 \helpref{wxSocketBase::Callback}{wxsocketbasecallback},
720 \helpref{wxSocketBase::CallbackData}{wxsocketbasecallbackdata}
721
722 \membersection{wxSocketBase::Callback}\label{wxsocketbasecallback}
723
724 \func{wxSocketBase::wxSockCbk}{Callback}{\param{wxSocketBase::wxSockCbk}{ callback}}
725
726 You can setup a callback function to be called when an event occurs. The function
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
730 \begin{verbatim}
731 void SocketCallback(wxSocketBase& sock, wxSocketNotify evt, char *cdata);
732 \end{verbatim}
733
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}).
736 The third parameter is the user data you specified using \helpref{CallbackData}{wxsocketbasecallbackdata}.
737
738 \wxheading{Return value}
739
740 A pointer to the previous callback.
741
742 \wxheading{See also}
743
744 \helpref{wxSocketBase::CallbackData}{wxsocketbasecallbackdata},
745 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
746 \helpref{wxSocketBase::Notify}{wxsocketbasenotify}
747
748 \membersection{wxSocketBase::CallbackData}\label{wxsocketbasecallbackdata}
749
750 \func{char *}{CallbackData}{\param{char *}{cdata}}
751
752 This function sets the the user data which will be passed to a
753 callback function set via \helpref{Callback}{wxsocketbasecallback}.
754
755 \wxheading{Return value}
756
757 A pointer to the previous user data.
758
759 \helpref{wxSocketBase::Callback}{wxsocketbasecallback},
760 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
761 \helpref{wxSocketBase::Notify}{wxsocketbasenotify}
762
763 % ---------------------------------------------------------------------------
764 % CLASS wxSocketClient
765 % ---------------------------------------------------------------------------
766 \section{\class{wxSocketClient}}\label{wxsocketclient}
767
768 \wxheading{Derived from}
769
770 \helpref{wxSocketBase}{wxsocketbase}
771
772 \wxheading{Include files}
773
774 <wx/socket.h>
775
776 % ---------------------------------------------------------------------------
777 % Members
778 % ---------------------------------------------------------------------------
779 %
780 % wxSocketClient
781 %
782 \membersection{wxSocketClient::wxSocketClient}
783
784 \func{}{wxSocketClient}{\param{wxSockFlags}{ flags = wxSocketBase::NONE}}
785
786 Constructs a new wxSocketClient.
787
788 \wxheading{Parameters}
789
790 \docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})}
791
792 %
793 % ~wxSocketClient
794 %
795 \membersection{wxSocketClient::\destruct{wxSocketClient}}
796
797 \func{}{\destruct{wxSocketClient}}{\void}
798
799 Destroys a wxSocketClient object.
800
801 %
802 % Connect
803 %
804 \membersection{wxSocketClient::Connect}\label{wxsocketclientconnect}
805
806 \func{bool}{Connect}{\param{wxSockAddress\&}{ address}, \param{bool}{ wait = TRUE}}
807
808 Connects to a server using the specified address.
809
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.
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.
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).
819
820 \wxheading{Parameters}
821
822 \docparam{address}{Address of the server.}
823
824 \docparam{wait}{If TRUE, waits for the connection to be ready.}
825
826 \wxheading{Return value}
827
828 Returns TRUE if the connection is established and no error occurs.
829
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
835 with WaitOnConnect or by watching {\bf wxSOCKET\_CONNECTION} and
836 {\bf wxSOCKET\_LOST} events.
837
838 \wxheading{See also}
839
840 \helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect},
841 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
842 \helpref{wxSocketBase::Notify}{wxsocketbasenotify}
843
844 %
845 % WaitOnConnect
846 %
847 \membersection{wxSocketClient::WaitOnConnect}\label{wxsocketclientwaitonconnect}
848
849 \func{bool}{WaitOnConnect}{\param{long}{ seconds = -1}, \param{long}{ milliseconds = 0}}
850
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.
865
866 \wxheading{See also}
867
868 \helpref{wxSocketClient::Connect}{wxsocketclientconnect}
869
870 % ---------------------------------------------------------------------------
871 % CLASS: wxSocketEvent
872 % ---------------------------------------------------------------------------
873 \section{\class{wxSocketEvent}}\label{wxsocketevent}
874
875 This event class contains information about socket events.
876
877 \wxheading{Derived from}
878
879 \helpref{wxEvent}{wxevent}
880
881 \wxheading{Include files}
882
883 <wx/socket.h>
884
885 \wxheading{Event table macros}
886
887 To process a socket event, use these event handler macros to direct input to member
888 functions that take a wxSocketEvent argument.
889
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}%
894
895 \wxheading{See also}
896
897 \helpref{wxSocketBase}{wxsocketbase},
898 \helpref{wxSocketClient}{wxsocketclient},
899 \helpref{wxSocketServer}{wxsocketserver}
900
901 \latexignore{\rtfignore{\wxheading{Members}}}
902
903 \membersection{wxSocketEvent::wxSocketEvent}
904
905 \func{}{wxSocketEvent}{\param{int}{ id = 0}}
906
907 Constructor.
908
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
916 \membersection{wxSocketEvent::SocketEvent}\label{wxsocketeventsocketevent}
917
918 \constfunc{wxSocketNotify}{SocketEvent}{\void}
919
920 Returns the socket event type.
921
922 % ---------------------------------------------------------------------------
923 % CLASS: wxSocketServer
924 % ---------------------------------------------------------------------------
925 \section{\class{wxSocketServer}}\label{wxsocketserver}
926
927 \wxheading{Derived from}
928
929 \helpref{wxSocketBase}{wxsocketbase}
930
931 \wxheading{Include files}
932
933 <wx/socket.h>
934
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
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
962 Destroys a wxSocketServer object (it doesn't close the accepted connections).
963
964 %
965 % Accept
966 %
967 \membersection{wxSocketServer::Accept}\label{wxsocketserveraccept}
968
969 \func{wxSocketBase *}{Accept}{\param{bool}{ wait = TRUE}}
970
971 Creates a new object wxSocketBase and accepts an incoming connection.
972
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
981 {\bf wxSOCKET\_CONNECTION} events, then call Accept once you know
982 that there is an incoming connection waiting to be accepted.
983
984 \wxheading{Return value}
985
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.
989
990 \wxheading{See also}
991
992 \helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept},
993 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
994 \helpref{wxSocketBase::Notify}{wxsocketbasenotify},
995 \helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
996
997 %
998 % AcceptWith
999 %
1000 \membersection{wxSocketServer::AcceptWith}\label{wxsocketserveracceptwith}
1001
1002 \func{bool}{AcceptWith}{\param{wxSocketBase\&}{ socket}, \param{bool}{ wait = TRUE}}
1003
1004 Accept an incoming connection using the specified socket object.
1005
1006 \wxheading{Parameters}
1007
1008 \docparam{socket}{Socket to be initialized}
1009
1010 \wxheading{Return value}
1011
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
1016 \helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept},
1017 \helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
1018 \helpref{wxSocketBase::Notify}{wxsocketbasenotify},
1019 \helpref{wxSocketServer::Accept}{wxsocketserveraccept} for a detailed explanation
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
1044 \helpref{wxSocketServer::Accept}{wxsocketserveraccept},
1045 \helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
1046