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