]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/socket.tex
Motif blindfix :-)
[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
261b9a3d 337This function waits until the socket is readable. This might mean that
7cd315c6 338queued data is available for reading or, for streamed sockets, that
261b9a3d
GRG
339the connection has been closed, so that a read operation will complete
340immediately without blocking (unless the {\bf wxSOCKET\_WAITALL} flag
341is set, in which case the operation might still block).
7cd315c6
GRG
342
343\membersection{wxSocketBase::IsDisconnected}\label{wxsocketbaseisdisconnected}
344
345%
346% IsDisconnected
347%
348\constfunc{bool}{IsDisconnected}{\void}
349
350Returns TRUE if the socket is not connected.
351
352\membersection{wxSocketBase::LastCount}\label{wxsocketbaselastcount}
353
354%
355% LastCount
356%
357\constfunc{wxUint32}{LastCount}{\void}
358
359Returns the number of bytes read or written by the last IO call.
360
361Use this function to get the number of bytes actually transferred
362after using one of the following IO calls: Discard, Peek, Read,
363ReadMsg, Unread, Write, WriteMsg.
364
365%
366% LastError
367%
368\membersection{wxSocketBase::LastError}\label{wxsocketbaselasterror}
369
370\constfunc{wxSocketError}{LastError}{\void}
371
372Returns the last wxSocket error. See \helpref{wxSocket errors}{wxsocketbase}.
373
374Please note that this function merely returns the last error code,
375but it should not be used to determine if an error has occured (this
376is because successful operations do not change the LastError value).
377Use \helpref{Error}{wxsocketbaseerror} first, in order to determine
378if the last IO call failed. If this returns TRUE, use LastError
379to discover the cause of the error.
380
381%
382% Notify
383%
384\membersection{wxSocketBase::Notify}\label{wxsocketbasenotify}
385
386\func{void}{Notify}{\param{bool}{ notify}}
387
388According to the {\it notify} value, this function enables
389or disables socket events. If {\it notify} is TRUE, the events
390configured with \helpref{SetNotify}{wxsocketbasesetnotify} will
391be sent to the application. If {\it notify} is FALSE; no events
392will be sent.
393
394%
395% Ok
396%
397\membersection{wxSocketBase::Ok}\label{wxsocketbaseok}
398
399\constfunc{bool}{Ok}{\void}
400
401Returns TRUE if the socket is initialized and ready and FALSE in other
402cases.
403
404%
405% RestoreState
406%
407\membersection{wxSocketBase::RestoreState}\label{wxsocketbaserestorestate}
408
409\func{void}{RestoreState}{\void}
410
411This function restores the previous state of the socket, as saved
412with \helpref{SaveState}{wxsocketbasesavestate}
413
414Calls to SaveState and RestoreState can be nested.
415
416\wxheading{See also}
417
418\helpref{wxSocketBase::SaveState}{wxsocketbasesavestate}
419
420%
421% SaveState
422%
423\membersection{wxSocketBase::SaveState}\label{wxsocketbasesavestate}
424
425\func{void}{SaveState}{\void}
426
427This function saves the current state of the socket in a stack. Socket
428state includes flags, as set with \helpref{SetFlags}{wxsocketbasesetflags},
429event mask, as set with \helpref{SetNotify}{wxsocketbasesetnotify} and
430\helpref{Notify}{wxsocketbasenotify}, and current settings for the
431asynchronous callbacks, as set with \helpref{Callback}{wxsocketbasecallback}
432and \helpref{CallbackData}{wxsocketbasecallbackdata}.
433
434Calls to SaveState and RestoreState can be nested.
435
436\wxheading{See also}
437
438\helpref{wxSocketBase::RestoreState}{wxsocketbaserestorestate}
439
440%
441% SetEventHandler
442%
443\membersection{wxSocketBase::SetEventHandler}\label{wxsocketbaseseteventhandler}
444
445\func{void}{SetEventHandler}{\param{wxEvtHandler\&}{ evt\_hdlr}, \param{int}{ id = -1}}
446
447Sets an event handler to be called when a socket event occurs. The
448handler will be called for those events for which notification is
449enabled with \helpref{SetNotify}{wxsocketbasesetnotify} and
450\helpref{Notify}{wxsocketbasenotify}.
451
452You can also specify a callback function to be called when an event
453occurs, although if possible, events should be used instead of callbacks.
454See \helpref{Callback}{wxsocketbasecallback} and
455\helpref{CallbackData}{wxsocketbasecallbackdata}.
456
457\wxheading{Parameters}
458
459\docparam{evt\_hdlr}{Specifies the event handler you want to use.}
460
461\docparam{id}{The id of socket event.}
462
463\wxheading{See also}
464
465\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
466\helpref{wxSocketBase::Notify}{wxsocketbasenotify},
467\helpref{wxSocketEvent}{wxsocketevent},
468\helpref{wxEvtHandler}{wxevthandler},
469\helpref{wxSocketBase::Callback}{wxsocketbasecallback},
470\helpref{wxSocketBase::CallbackData}{wxsocketbasecallbackdata}
471
472%
473% SetFlags
474%
5a96d2f4
GL
475\membersection{wxSocketBase::SetFlags}\label{wxsocketbasesetflags}
476
477\func{void}{SetFlags}{\param{wxSocketBase::wxSockFlags}{ flags}}
478
479\twocolwidtha{7cm}
480\begin{twocollist}\itemsep=0pt
a4625b8c
GRG
481\twocolitem{{\bf wxSOCKET\_NONE}}{Normal functionality.}
482\twocolitem{{\bf wxSOCKET\_NOWAIT}}{Read/write as much data as possible and return immediately.}
483\twocolitem{{\bf wxSOCKET\_WAITALL}}{Wait for all required data to be read/written unless an error occurs.}
105521d1 484\twocolitem{{\bf wxSOCKET\_BLOCK}}{Block the GUI (do not yield) while reading/writing data.}
5a96d2f4
GL
485\end{twocollist}
486
cf85cb95
GRG
487A brief overview on how to use these flags follows.
488
489If no flag is specified (this is the same as {\bf wxSOCKET\_NONE}),
490IO calls will return after some data has been read or written, even
491when the transfer might not be complete. This is the same as issuing
492exactly one blocking low-level call to recv() or send(). Note that
105521d1 493{\it blocking} here refers to when the function returns, not to whether
cf85cb95
GRG
494the GUI blocks during this time.
495
496If {\bf wxSOCKET\_NOWAIT} is specified, IO calls will return immediately.
497Read operations will retrieve only available data. Write operations will
498write as much data as possible, depending on how much space is available
499in the output buffer. This is the same as issuing exactly one nonblocking
105521d1
GRG
500low-level call to recv() or send(). Note that {\it nonblocking} here
501refers to when the function returns, not to whether the GUI blocks during
502this time.
cf85cb95
GRG
503
504If {\bf wxSOCKET\_WAITALL} is specified, IO calls won't return until ALL
505the data has been read or written (or until an error occurs), blocking if
506necessary, and issuing several low level calls if necessary. This is the
507same as having a loop which makes as many blocking low-level calls to
508recv() or send() as needed so as to transfer all the data. Note that
105521d1 509{\it blocking} here refers to when the function returns, not to whether
cf85cb95
GRG
510the GUI blocks during this time.
511
bf9b6711 512The {\bf wxSOCKET\_BLOCK} flag controls whether the GUI blocks during
105521d1
GRG
513IO operations. If this flag is specified, the socket will not yield
514during IO calls, so the GUI will remain blocked until the operation
515completes. If it is not used, then the application must take extra
516care to avoid unwanted reentrance.
cf85cb95
GRG
517
518So:
519
a4625b8c 520{\bf wxSOCKET\_NONE} will try to read at least SOME data, no matter how much.
407f3681 521
cf85cb95
GRG
522{\bf wxSOCKET\_NOWAIT} will always return immediately, even if it cannot
523read or write ANY data.
407f3681 524
cf85cb95
GRG
525{\bf wxSOCKET\_WAITALL} will only return when it has read or written ALL
526the data.
407f3681 527
cf85cb95 528{\bf wxSOCKET\_BLOCK} has nothing to do with the previous flags and
bf9b6711 529it controls whether the GUI blocks.
cf85cb95 530
5a96d2f4
GL
531%
532% SetNotify
533%
534\membersection{wxSocketBase::SetNotify}\label{wxsocketbasesetnotify}
535
cf85cb95 536\func{void}{SetNotify}{\param{wxSocketEventFlags}{ flags}}
5a96d2f4 537
cf85cb95
GRG
538SetNotify specifies which socket events are to be sent to the event handler.
539The {\it flags} parameter is a combination of flags ORed toghether. The
540following flags can be used:
aa6d9706
GL
541
542\twocolwidtha{7cm}
543\begin{twocollist}\itemsep=0pt
cf85cb95
GRG
544\twocolitem{{\bf wxSOCKET\_INPUT\_FLAG}}{to receive wxSOCKET\_INPUT}
545\twocolitem{{\bf wxSOCKET\_OUTPUT\_FLAG}}{to receive wxSOCKET\_OUTPUT}
546\twocolitem{{\bf wxSOCKET\_CONNECTION\_FLAG}}{to receive wxSOCKET\_CONNECTION}
547\twocolitem{{\bf wxSOCKET\_LOST\_FLAG}}{to receive wxSOCKET\_LOST}
a4625b8c 548\end{twocollist}
aa6d9706
GL
549
550For example:
407f3681 551
aa6d9706 552\begin{verbatim}
cf85cb95 553 sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
105521d1 554 sock.Notify(TRUE);
aa6d9706 555\end{verbatim}
407f3681 556
cf85cb95
GRG
557In this example, the user will be notified about incoming socket data and
558whenever the connection is closed.
aa6d9706 559
7e9a386e 560For more information on socket events see \helpref{wxSocket events}{wxsocketbase}.
aa6d9706
GL
561
562%
563% SetTimeout
564%
bf9b6711 565\membersection{wxSocketBase::SetTimeout}\label{wxsocketbasesettimeout}
7e9a386e 566
aa6d9706
GL
567\func{void}{SetTimeout}{\param{int }{seconds}}
568
7cd315c6
GRG
569This function sets the default socket timeout in seconds. This timeout
570applies to all IO calls, and also to the \helpref{Wait}{wxsocketbasewait}
571family of functions if you don't specify a wait interval. Initially, the
572default is set to 10 minutes.
e79848ac 573
e79848ac
GL
574%
575% Peek
576%
e79848ac
GL
577\membersection{wxSocketBase::Peek}\label{wxsocketbasepeek}
578
aa6d9706 579\func{wxSocketBase\&}{Peek}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac 580
a4625b8c
GRG
581This function peeks a buffer of {\it nbytes} bytes from the socket.
582Peeking a buffer doesn't delete it from the socket input queue.
e79848ac 583
105521d1 584Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually peeked.
cf85cb95 585
105521d1 586Use \helpref{Error}{wxsocketbaseerror} to determine if the operation succeeded.
cf85cb95 587
e79848ac
GL
588\wxheading{Parameters}
589
590\docparam{buffer}{Buffer where to put peeked data.}
42ff6409 591
e79848ac
GL
592\docparam{nbytes}{Number of bytes.}
593
42ff6409
JS
594\wxheading{Return value}
595
e79848ac
GL
596Returns a reference to the current object.
597
cf85cb95
GRG
598\wxheading{Remark/Warning}
599
7cd315c6 600The exact behaviour of wxSocketBase::Peek depends on the combination
cf85cb95
GRG
601of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
602
e79848ac
GL
603\wxheading{See also}
604
407f3681
JS
605\helpref{wxSocketBase::Error}{wxsocketbaseerror},
606\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
607\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
cf85cb95 608\helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
e79848ac
GL
609
610%
611% Read
612%
e79848ac
GL
613\membersection{wxSocketBase::Read}\label{wxsocketbaseread}
614
aa6d9706 615\func{wxSocketBase\&}{Read}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac
GL
616
617This function reads a buffer of {\it nbytes} bytes from the socket.
618
105521d1 619Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually read.
cf85cb95 620
105521d1 621Use \helpref{Error}{wxsocketbaseerror} to determine if the operation succeeded.
cf85cb95 622
e79848ac
GL
623\wxheading{Parameters}
624
625\docparam{buffer}{Buffer where to put read data.}
42ff6409 626
e79848ac
GL
627\docparam{nbytes}{Number of bytes.}
628
42ff6409
JS
629\wxheading{Return value}
630
e79848ac
GL
631Returns a reference to the current object.
632
9f3430a6
GL
633\wxheading{Remark/Warning}
634
7cd315c6 635The exact behaviour of wxSocketBase::Read depends on the combination
407f3681 636of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}.
cf85cb95 637
e79848ac
GL
638\wxheading{See also}
639
407f3681
JS
640\helpref{wxSocketBase::Error}{wxsocketbaseerror},
641\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
642\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
cf85cb95 643\helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
e79848ac 644
e79848ac
GL
645%
646% ReadMsg
647%
e79848ac
GL
648\membersection{wxSocketBase::ReadMsg}\label{wxsocketbasereadmsg}
649
aa6d9706 650\func{wxSocketBase\&}{ReadMsg}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac 651
105521d1
GRG
652This function reads a buffer sent by \helpref{WriteMsg}{wxsocketbasewritemsg}
653on a socket. If the buffer passed to the function isn't big enough, the
654remaining bytes will be discarded. This function always waits for the
655buffer to be entirely filled, unless an error occurs.
cf85cb95 656
105521d1 657Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually read.
cf85cb95 658
105521d1 659Use \helpref{Error}{wxsocketbaseerror} to determine if the operation succeeded.
e79848ac
GL
660
661\wxheading{Parameters}
662
663\docparam{buffer}{Buffer where to put read data.}
42ff6409 664
105521d1 665\docparam{nbytes}{Size of the buffer.}
e79848ac 666
42ff6409
JS
667\wxheading{Return value}
668
e79848ac
GL
669Returns a reference to the current object.
670
cf85cb95
GRG
671\wxheading{Remark/Warning}
672
7cd315c6 673wxSocketBase::ReadMsg will behave as if the {\bf wxSOCKET\_WAITALL} flag
a4625b8c
GRG
674was always set and it will always ignore the {\bf wxSOCKET\_NOWAIT} flag.
675The exact behaviour of ReadMsg depends on the {\bf wxSOCKET\_BLOCK} flag.
676For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}.
cf85cb95 677
e79848ac
GL
678\wxheading{See also}
679
407f3681
JS
680\helpref{wxSocketBase::Error}{wxsocketbaseerror},
681\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
682\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
683\helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags},
9f3430a6 684\helpref{wxSocketBase::WriteMsg}{wxsocketbasewritemsg}
e79848ac
GL
685
686%
687% Unread
688%
09eea162 689\membersection{wxSocketBase::Unread}\label{wxsocketbaseunread}
e79848ac 690
aa6d9706 691\func{wxSocketBase\&}{Unread}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac 692
cf85cb95
GRG
693This function unreads a buffer. That is, the data in the buffer is put back
694in the incoming queue. This function is not affected by wxSocket flags.
695
105521d1 696If you use \helpref{LastCount}{wxsocketbaselastcount}, it will always return {\it nbytes}.
cf85cb95 697
105521d1 698If you use \helpref{Error}{wxsocketbaseerror}, it will always return FALSE.
e79848ac
GL
699
700\wxheading{Parameters}
701
702\docparam{buffer}{Buffer to be unread.}
42ff6409 703
e79848ac
GL
704\docparam{nbytes}{Number of bytes.}
705
42ff6409
JS
706\wxheading{Return value}
707
e79848ac
GL
708Returns a reference to the current object.
709
710\wxheading{See also}
711
407f3681
JS
712\helpref{wxSocketBase::Error}{wxsocketbaseerror},
713\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
9f3430a6 714\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
e79848ac
GL
715
716%
7cd315c6 717% Wait
e79848ac 718%
e79848ac 719\membersection{wxSocketBase::Wait}\label{wxsocketbasewait}
42ff6409 720
aa6d9706 721\func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
e79848ac 722
105521d1
GRG
723This function waits until one of the following conditions is TRUE. Note
724that it is recommended to use the individual Wait functions to wait for
725the required condition, instead of this one.
726
727\begin{itemize}
7cd315c6 728\item The socket becomes readable.
105521d1
GRG
729\item The socket becomes writable.
730\item An ongoing connection request has completed (only for clients)
731\item An incoming connection request has arrived (only for servers)
732\item The connection has been closed.
733\end{itemize}
e79848ac
GL
734
735\wxheading{Parameters}
736
105521d1
GRG
737\docparam{seconds}{Number of seconds to wait.
738If -1, it will wait for the default timeout,
739as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.}
42ff6409 740
aa6d9706 741\docparam{millisecond}{Number of milliseconds to wait.}
e79848ac 742
42ff6409 743\wxheading{Return value}
e79848ac 744
105521d1
GRG
745Returns TRUE when any of the above conditions is satisfied,
746FALSE if the timeout was reached.
e79848ac
GL
747
748\wxheading{See also}
749
407f3681
JS
750\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
751\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
9f3430a6 752\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
e79848ac
GL
753
754%
755% WaitForRead
756%
e79848ac 757\membersection{wxSocketBase::WaitForRead}\label{wxsocketbasewaitforread}
42ff6409 758
aa6d9706 759\func{bool}{WaitForRead}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
e79848ac 760
7cd315c6
GRG
761This function waits until the socket is readable. This might mean that
762queued data is available for reading or, for streamed sockets, that
261b9a3d
GRG
763the connection has been closed, so that a read operation will complete
764immediately without blocking (unless the {\bf wxSOCKET\_WAITALL} flag
765is set, in which case the operation might still block).
e79848ac
GL
766
767\wxheading{Parameters}
768
105521d1
GRG
769\docparam{seconds}{Number of seconds to wait.
770If -1, it will wait for the default timeout,
771as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.}
42ff6409 772
aa6d9706 773\docparam{millisecond}{Number of milliseconds to wait.}
e79848ac 774
42ff6409 775\wxheading{Return value}
e79848ac 776
261b9a3d 777Returns TRUE if the socket becomes readable, FALSE on timeout.
e79848ac
GL
778
779\wxheading{See also}
780
407f3681
JS
781\helpref{wxSocketBase::Wait}{wxsocketbasewait},
782\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
9f3430a6 783\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
e79848ac
GL
784
785%
786% WaitForWrite
787%
e79848ac 788\membersection{wxSocketBase::WaitForWrite}\label{wxsocketbasewaitforwrite}
42ff6409 789
aa6d9706 790\func{bool}{WaitForWrite}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
e79848ac 791
7cd315c6
GRG
792This function waits until the socket becomes writable. This might mean that
793the socket is ready to send new data, or for streamed sockets, that the
261b9a3d
GRG
794connection has been closed, so that a write operation is guaranteed to
795complete immediately (unless the {\bf wxSOCKET\_WAITALL} flag is set,
796in which case the operation might still block).
e79848ac
GL
797
798\wxheading{Parameters}
799
105521d1
GRG
800\docparam{seconds}{Number of seconds to wait.
801If -1, it will wait for the default timeout,
802as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.}
42ff6409 803
aa6d9706 804\docparam{millisecond}{Number of milliseconds to wait.}
e79848ac 805
42ff6409 806\wxheading{Return value}
e79848ac 807
261b9a3d 808Returns TRUE if the socket becomes writable, FALSE on timeout.
e79848ac
GL
809
810\wxheading{See also}
811
407f3681
JS
812\helpref{wxSocketBase::Wait}{wxsocketbasewait},
813\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
9f3430a6 814\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
e79848ac
GL
815
816%
817% WaitForLost
818%
e79848ac 819\membersection{wxSocketBase::WaitForLost}\label{wxsocketbasewaitforlost}
42ff6409 820
aa6d9706 821\func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
e79848ac 822
105521d1
GRG
823This function waits until the connection is lost. This may happen if
824the peer gracefully closes the connection or if the connection breaks.
e79848ac
GL
825
826\wxheading{Parameters}
827
105521d1
GRG
828\docparam{seconds}{Number of seconds to wait.
829If -1, it will wait for the default timeout,
830as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.}
42ff6409 831
aa6d9706 832\docparam{millisecond}{Number of milliseconds to wait.}
e79848ac 833
42ff6409 834\wxheading{Return value}
e79848ac 835
cf85cb95 836Returns TRUE if the connection was lost, FALSE if the timeout was reached.
e79848ac
GL
837
838\wxheading{See also}
839
407f3681
JS
840\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
841\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
9f3430a6 842\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
42ff6409
JS
843
844%
7cd315c6 845% Write
42ff6409 846%
7cd315c6 847\membersection{wxSocketBase::Write}\label{wxsocketbasewrite}
42ff6409 848
7cd315c6 849\func{wxSocketBase\&}{Write}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
42ff6409 850
7cd315c6 851This function writes a buffer of {\it nbytes} bytes to the socket.
e79848ac 852
7cd315c6 853Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually written.
42ff6409 854
7cd315c6 855Use \helpref{Error}{wxsocketbaseerror} to determine if the operation succeeded.
e79848ac 856
7cd315c6 857\wxheading{Parameters}
cf85cb95 858
7cd315c6 859\docparam{buffer}{Buffer with the data to be sent.}
e79848ac 860
7cd315c6 861\docparam{nbytes}{Number of bytes.}
e79848ac 862
7cd315c6 863\wxheading{Return value}
aa6d9706 864
7cd315c6 865Returns a reference to the current object.
7e9a386e 866
7cd315c6 867\wxheading{Remark/Warning}
aa6d9706 868
7cd315c6
GRG
869The exact behaviour of wxSocketBase::Write depends on the combination
870of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}.
aa6d9706 871
7cd315c6 872\wxheading{See also}
aa6d9706 873
7cd315c6
GRG
874\helpref{wxSocketBase::Error}{wxsocketbaseerror},
875\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
876\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
877\helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
aa6d9706
GL
878
879%
7cd315c6 880% WriteMsg
aa6d9706 881%
7cd315c6 882\membersection{wxSocketBase::WriteMsg}\label{wxsocketbasewritemsg}
e79848ac 883
7cd315c6 884\func{wxSocketBase\&}{WriteMsg}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac 885
7cd315c6
GRG
886This function writes a buffer of {\it nbytes} bytes from the socket, but it
887writes a short header before so that \helpref{ReadMsg}{wxsocketbasereadmsg}
888knows how much data should it actually read. So, a buffer sent with WriteMsg
889{\bf must} be read with ReadMsg. This function always waits for the entire
890buffer to be sent, unless an error occurs.
e79848ac 891
7cd315c6 892Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually written.
cf85cb95 893
7cd315c6 894Use \helpref{Error}{wxsocketbaseerror} to determine if the operation succeeded.
e79848ac
GL
895
896\wxheading{Parameters}
897
7cd315c6 898\docparam{buffer}{Buffer with the data to be sent.}
105521d1 899
7cd315c6 900\docparam{nbytes}{Number of bytes to send.}
aa6d9706
GL
901
902\wxheading{Return value}
903
7cd315c6 904Returns a reference to the current object.
aa6d9706 905
7cd315c6 906\wxheading{Remark/Warning}
aa6d9706 907
7cd315c6
GRG
908wxSocketBase::WriteMsg will behave as if the {\bf wxSOCKET\_WAITALL} flag
909was always set and it will always ignore the {\bf wxSOCKET\_NOWAIT} flag.
910The exact behaviour of WriteMsg depends on the {\bf wxSOCKET\_BLOCK} flag.
911For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}.
105521d1 912
7cd315c6 913\wxheading{See also}
aa6d9706 914
7cd315c6
GRG
915\helpref{wxSocketBase::Error}{wxsocketbaseerror},
916\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
917\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
918\helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags},
919\helpref{wxSocketBase::ReadMsg}{wxsocketbasereadmsg}
cf85cb95 920
e79848ac
GL
921
922% ---------------------------------------------------------------------------
923% CLASS wxSocketClient
924% ---------------------------------------------------------------------------
7cd315c6 925
e79848ac
GL
926\section{\class{wxSocketClient}}\label{wxsocketclient}
927
928\wxheading{Derived from}
929
930\helpref{wxSocketBase}{wxsocketbase}
931
954b8ae6
JS
932\wxheading{Include files}
933
934<wx/socket.h>
935
e79848ac
GL
936% ---------------------------------------------------------------------------
937% Members
938% ---------------------------------------------------------------------------
e79848ac
GL
939%
940% wxSocketClient
941%
e79848ac 942\membersection{wxSocketClient::wxSocketClient}
42ff6409 943
e79848ac
GL
944\func{}{wxSocketClient}{\param{wxSockFlags}{ flags = wxSocketBase::NONE}}
945
105521d1 946Constructor.
42ff6409 947
e79848ac
GL
948\wxheading{Parameters}
949
950\docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})}
951
952%
953% ~wxSocketClient
954%
e79848ac 955\membersection{wxSocketClient::\destruct{wxSocketClient}}
42ff6409 956
e79848ac
GL
957\func{}{\destruct{wxSocketClient}}{\void}
958
105521d1 959Destructor.
e79848ac
GL
960
961%
962% Connect
963%
42ff6409 964\membersection{wxSocketClient::Connect}\label{wxsocketclientconnect}
e79848ac 965
e79848ac
GL
966\func{bool}{Connect}{\param{wxSockAddress\&}{ address}, \param{bool}{ wait = TRUE}}
967
cf85cb95
GRG
968Connects to a server using the specified address.
969
105521d1
GRG
970If {\it wait} is TRUE, Connect will wait until the connection completes.
971{\bf Warning:} This will block the GUI.
cf85cb95
GRG
972
973If {\it wait} is FALSE, Connect will try to establish the connection and
974return immediately, without blocking the GUI. When used this way, even if
975Connect returns FALSE, the connection request can be completed later.
105521d1
GRG
976To detect this, use \helpref{WaitOnConnect}{wxsocketclientwaitonconnect},
977or catch {\bf wxSOCKET\_CONNECTION} events (for successful establishment)
978and {\bf wxSOCKET\_LOST} events (for connection failure).
e79848ac
GL
979
980\wxheading{Parameters}
981
982\docparam{address}{Address of the server.}
42ff6409 983
105521d1 984\docparam{wait}{If TRUE, waits for the connection to complete.}
e79848ac
GL
985
986\wxheading{Return value}
987
988Returns TRUE if the connection is established and no error occurs.
989
cf85cb95
GRG
990If {\it wait} was TRUE, and Connect returns FALSE, an error occured
991and the connection failed.
992
993If {\it wait} was FALSE, and Connect returns FALSE, you should still
994be prepared to handle the completion of this connection request, either
105521d1
GRG
995with \helpref{WaitOnConnect}{wxsocketclientwaitonconnect} or by watching
996{\bf wxSOCKET\_CONNECTION} and {\bf wxSOCKET\_LOST} events.
cf85cb95 997
e79848ac
GL
998\wxheading{See also}
999
407f3681
JS
1000\helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect},
1001\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
cf85cb95 1002\helpref{wxSocketBase::Notify}{wxsocketbasenotify}
e79848ac
GL
1003
1004%
1005% WaitOnConnect
1006%
42ff6409 1007\membersection{wxSocketClient::WaitOnConnect}\label{wxsocketclientwaitonconnect}
e79848ac 1008
aa6d9706 1009\func{bool}{WaitOnConnect}{\param{long}{ seconds = -1}, \param{long}{ milliseconds = 0}}
e79848ac 1010
105521d1
GRG
1011Wait until a connection request completes, or until the specified timeout
1012elapses. Use this function after issuing a call to \helpref{Connect}{wxsocketclientconnect}
1013with {\it wait} set to FALSE.
cf85cb95
GRG
1014
1015\wxheading{Parameters}
1016
105521d1
GRG
1017\docparam{seconds}{Number of seconds to wait.
1018If -1, it will wait for the default timeout,
1019as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.}
cf85cb95
GRG
1020
1021\docparam{millisecond}{Number of milliseconds to wait.}
1022
1023\wxheading{Return value}
1024
261b9a3d
GRG
1025WaitOnConnect returns TRUE if the connection request completes. This
1026does not necessarily mean that the connection was succesfully established;
1027it might also happen that the connection was refused by the peer. Use
1028\helpref{IsConnected}{wxsocketbaseisconnected} to distinguish between
1029these two situations.
1030
1031If the timeout elapses, WaitOnConnect returns FALSE.
1032
1033These semantics allow code like this:
cf85cb95 1034
261b9a3d
GRG
1035\begin{verbatim}
1036// Issue the connection request
1037client->Connect(addr, FALSE);
1038
1039// Wait until the request completes or until we decide to give up
1040bool waitmore;
1041while ( !WaitOnConnect(seconds, millis) && waitmore )
1042{
1043 // possibly give some feedback to the user,
1044 // and update waitmore if needed.
1045}
1046bool success = client->IsConnected();
1047\end{verbatim}
e79848ac
GL
1048
1049\wxheading{See also}
1050
105521d1
GRG
1051\helpref{wxSocketClient::Connect}{wxsocketclientconnect},
1052\helpref{wxSocketBase::IsConnected}{wxsocketbaseisconnected}
e79848ac
GL
1053
1054% ---------------------------------------------------------------------------
42ff6409 1055% CLASS: wxSocketEvent
e79848ac 1056% ---------------------------------------------------------------------------
42ff6409 1057\section{\class{wxSocketEvent}}\label{wxsocketevent}
e79848ac 1058
42ff6409 1059This event class contains information about socket events.
e79848ac
GL
1060
1061\wxheading{Derived from}
1062
42ff6409 1063\helpref{wxEvent}{wxevent}
e79848ac 1064
954b8ae6
JS
1065\wxheading{Include files}
1066
1067<wx/socket.h>
1068
42ff6409 1069\wxheading{Event table macros}
e79848ac 1070
42ff6409
JS
1071To process a socket event, use these event handler macros to direct input to member
1072functions that take a wxSocketEvent argument.
e79848ac 1073
42ff6409
JS
1074\twocolwidtha{7cm}
1075\begin{twocollist}\itemsep=0pt
1076\twocolitem{{\bf EVT\_SOCKET(id, func)}}{Process a socket event, supplying the member function.}
105521d1 1077\end{twocollist}
e79848ac
GL
1078
1079\wxheading{See also}
1080
407f3681
JS
1081\helpref{wxSocketBase}{wxsocketbase},
1082\helpref{wxSocketClient}{wxsocketclient},
42ff6409 1083\helpref{wxSocketServer}{wxsocketserver}
e79848ac 1084
42ff6409 1085\latexignore{\rtfignore{\wxheading{Members}}}
e79848ac 1086
42ff6409 1087\membersection{wxSocketEvent::wxSocketEvent}
e79848ac 1088
42ff6409 1089\func{}{wxSocketEvent}{\param{int}{ id = 0}}
e79848ac 1090
42ff6409 1091Constructor.
e79848ac 1092
e5a2291a
GRG
1093\membersection{wxSocketEvent::Socket}\label{wxsocketeventsocket}
1094
1095\constfunc{wxSocketBase *}{Socket}{\void}
1096
1097Returns the socket object to which this event refers to. This makes
1098it possible to use the same event handler for different sockets.
1099
42ff6409 1100\membersection{wxSocketEvent::SocketEvent}\label{wxsocketeventsocketevent}
e79848ac 1101
aa6d9706 1102\constfunc{wxSocketNotify}{SocketEvent}{\void}
e79848ac 1103
42ff6409 1104Returns the socket event type.
e79848ac 1105
42ff6409
JS
1106% ---------------------------------------------------------------------------
1107% CLASS: wxSocketServer
1108% ---------------------------------------------------------------------------
1109\section{\class{wxSocketServer}}\label{wxsocketserver}
1110
1111\wxheading{Derived from}
1112
1113\helpref{wxSocketBase}{wxsocketbase}
1114
954b8ae6
JS
1115\wxheading{Include files}
1116
1117<wx/socket.h>
1118
42ff6409
JS
1119% ---------------------------------------------------------------------------
1120% Members
1121% ---------------------------------------------------------------------------
1122\latexignore{\rtfignore{\wxheading{Members}}}
1123
1124%
1125% wxSocketServer
1126%
1127\membersection{wxSocketServer::wxSocketServer}\label{wxsocketserverconstr}
1128
1129\func{}{wxSocketServer}{\param{wxSockAddress\&}{ address}, \param{wxSockFlags}{ flags = wxSocketBase::NONE}}
1130
105521d1
GRG
1131Constructs a new server and tries to bind to the specified {\it address}.
1132Before trying to accept new connections, test whether it succeeded with
1133\helpref{wxSocketBase::Ok}{wxsocketbaseok}.
42ff6409 1134
42ff6409
JS
1135\wxheading{Parameters}
1136
1137\docparam{address}{Specifies the local address for the server (e.g. port number).}
1138
1139\docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})}
1140
1141%
1142% ~wxSocketServer
1143%
1144\membersection{wxSocketServer::\destruct{wxSocketServer}}
1145
1146\func{}{\destruct{wxSocketServer}}{\void}
1147
105521d1 1148Destructor (it doesn't close the accepted connections).
42ff6409
JS
1149
1150%
1151% Accept
1152%
1fb3eae5 1153\membersection{wxSocketServer::Accept}\label{wxsocketserveraccept}
42ff6409 1154
cf85cb95
GRG
1155\func{wxSocketBase *}{Accept}{\param{bool}{ wait = TRUE}}
1156
105521d1
GRG
1157Accepts an incoming connection request, and creates a new
1158\helpref{wxSocketBase}{wxsocketbase} object which represents
1159the server-side of the connection.
42ff6409 1160
cf85cb95
GRG
1161If {\it wait} is TRUE and there are no pending connections to be
1162accepted, it will wait for the next incoming connection to arrive.
105521d1 1163{\bf Warning:} This will block the GUI.
cf85cb95
GRG
1164
1165If {\it wait} is FALSE, it will try to accept a pending connection
105521d1
GRG
1166if there is one, but it will always return immediately without blocking
1167the GUI. If you want to use Accept in this way, you can either check for
1168incoming connections with \helpref{WaitForAccept}{wxsocketserverwaitforaccept}
7cd315c6 1169or catch {\bf wxSOCKET\_CONNECTION} events, then call Accept once you know
a4625b8c 1170that there is an incoming connection waiting to be accepted.
42ff6409
JS
1171
1172\wxheading{Return value}
1173
cf85cb95
GRG
1174Returns an opened socket connection, or NULL if an error occured or
1175if the {\it wait} parameter was FALSE and there were no pending
1176connections.
42ff6409
JS
1177
1178\wxheading{See also}
1179
1fb3eae5 1180\helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept},
407f3681
JS
1181\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
1182\helpref{wxSocketBase::Notify}{wxsocketbasenotify},
42ff6409
JS
1183\helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
1184
1185%
1186% AcceptWith
1187%
1188\membersection{wxSocketServer::AcceptWith}\label{wxsocketserveracceptwith}
1189
cf85cb95 1190\func{bool}{AcceptWith}{\param{wxSocketBase\&}{ socket}, \param{bool}{ wait = TRUE}}
42ff6409
JS
1191
1192Accept an incoming connection using the specified socket object.
42ff6409
JS
1193
1194\wxheading{Parameters}
1195
1196\docparam{socket}{Socket to be initialized}
1197
1198\wxheading{Return value}
1199
cf85cb95
GRG
1200Returns TRUE on success, or FALSE if an error occured or if the
1201{\it wait} parameter was FALSE and there were no pending
1202connections.
1203
1fb3eae5 1204\helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept},
407f3681
JS
1205\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
1206\helpref{wxSocketBase::Notify}{wxsocketbasenotify},
bf9b6711 1207\helpref{wxSocketServer::Accept}{wxsocketserveraccept} for a detailed explanation
cf85cb95
GRG
1208
1209%
1210% WaitForAccept
1211%
1212\membersection{wxSocketServer::WaitForAccept}\label{wxsocketserverwaitforaccept}
1213
1214\func{bool}{WaitForAccept}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
1215
1216This function waits for an incoming connection. Use it if you want to call
105521d1
GRG
1217\helpref{Accept}{wxsocketserveraccept} or \helpref{AcceptWith}{wxsocketserveracceptwith}
1218with {\it wait} set to FALSE, to detect when an incoming connection is waiting
1219to be accepted.
cf85cb95
GRG
1220
1221\wxheading{Parameters}
1222
105521d1
GRG
1223\docparam{seconds}{Number of seconds to wait.
1224If -1, it will wait for the default timeout,
1225as set with \helpref{SetTimeout}{wxsocketbasesettimeout}.}
cf85cb95
GRG
1226
1227\docparam{millisecond}{Number of milliseconds to wait.}
1228
1229\wxheading{Return value}
1230
105521d1 1231Returns TRUE if an incoming connection arrived, FALSE if the timeout elapsed.
cf85cb95
GRG
1232
1233\wxheading{See also}
1234
407f3681 1235\helpref{wxSocketServer::Accept}{wxsocketserveraccept},
cf85cb95
GRG
1236\helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
1237