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