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