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