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