]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/socket.tex
Documented wxStopWatch and wxToolBar::AddControl().
[wxWidgets.git] / docs / latex / wx / socket.tex
CommitLineData
e79848ac
GL
1\section{\class{wxSocketBase}}\label{wxsocketbase}
2
3\wxheading{Derived from}
4
5\helpref{wxEvtHandler}{wxevthandler}
6
954b8ae6
JS
7\wxheading{Include files}
8
9<wx/socket.h>
10
407f3681 11\wxheading{wxSocket errors}
aa6d9706
GL
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.}
cf85cb95
GRG
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.}
aa6d9706
GL
24\twocolitem{{\bf wxSOCKET\_MEMERR}}{Memory exhausted.}
25\end{twocollist}%
26
7e9a386e 27\wxheading{wxSocket events}
5a96d2f4 28
aa6d9706
GL
29\twocolwidtha{7cm}
30\begin{twocollist}\itemsep=0pt
cf85cb95 31\twocolitem{{\bf wxSOCKET\_INPUT}}{Some data has arrived to the socket.}
aa6d9706 32\twocolitem{{\bf wxSOCKET\_OUTPUT}}{The socket is ready to be written to.}
cf85cb95
GRG
33\twocolitem{{\bf wxSOCKET\_CONNECTION}}{Incoming connection arrival (server), or connection establishment (client).}
34\twocolitem{{\bf wxSOCKET\_LOST}}{The connection has been closed.}
aa6d9706
GL
35\twocolitem{{\bf wxSOCKET\_MAX\_EVENT}}{This should never happen but the compiler may complain about it.}
36\end{twocollist}%
5a96d2f4 37
cf85cb95
GRG
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
e79848ac
GL
57% ---------------------------------------------------------------------------
58% Event handling
59% ---------------------------------------------------------------------------
60\wxheading{Event handling}
61
62To process events from a socket, use the following event handler macro to direct
cf85cb95 63input to member functions that take a \helpref{wxSocketEvent}{wxsocketevent} argument.
e79848ac 64
42ff6409 65\twocolwidtha{7cm}%
e79848ac
GL
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% ---------------------------------------------------------------------------
e79848ac
GL
73\wxheading{See also}
74
407f3681
JS
75\helpref{wxSocketEvent}{wxsocketevent},
76\helpref{wxSocketClient}{wxsocketclient},
9f3430a6 77\helpref{wxSocketServer}{wxsocketserver}
e79848ac
GL
78
79% ---------------------------------------------------------------------------
80% Members
81% ---------------------------------------------------------------------------
e79848ac
GL
82\latexignore{\rtfignore{\wxheading{Members}}}
83
84\membersection{wxSocketBase::wxSocketBase}
42ff6409 85
e79848ac
GL
86\func{}{wxSocketBase}{\void}
87
407f3681 88Default constructor. Don't use it; use \helpref{wxSocketClient}{wxsocketclient}
e79848ac
GL
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
5a96d2f4
GL
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
cf85cb95
GRG
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.}
407f3681 114\twocolitem{{\bf wxSOCKET\_BLOCK}}{Block the GUI (do not wxYield) while reading/writing data.}
5a96d2f4
GL
115\end{twocollist}
116
cf85cb95
GRG
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.
407f3681 148
cf85cb95
GRG
149{\bf wxSOCKET\_NOWAIT} will always return immediately, even if it cannot
150read or write ANY data.
407f3681 151
cf85cb95
GRG
152{\bf wxSOCKET\_WAITALL} will only return when it has read or written ALL
153the data.
407f3681 154
cf85cb95
GRG
155{\bf wxSOCKET\_BLOCK} has nothing to do with the previous flags and
156it control whether the GUI blocks.
157
5a96d2f4
GL
158%
159% SetNotify
160%
161\membersection{wxSocketBase::SetNotify}\label{wxsocketbasesetnotify}
162
cf85cb95 163\func{void}{SetNotify}{\param{wxSocketEventFlags}{ flags}}
5a96d2f4 164
cf85cb95
GRG
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:
aa6d9706
GL
168
169\twocolwidtha{7cm}
170\begin{twocollist}\itemsep=0pt
cf85cb95
GRG
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}
aa6d9706
GL
175\end{twocollist}%
176
177For example:
407f3681 178
aa6d9706 179\begin{verbatim}
cf85cb95 180 sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
aa6d9706 181\end{verbatim}
407f3681 182
cf85cb95
GRG
183In this example, the user will be notified about incoming socket data and
184whenever the connection is closed.
aa6d9706 185
7e9a386e 186For more information on socket events see \helpref{wxSocket events}{wxsocketbase}.
aa6d9706
GL
187
188%
189% SetTimeout
190%
191\membersection{wxSocketBase::SetTimeout}{wxsocketbasesettimeout}
7e9a386e 192
aa6d9706
GL
193\func{void}{SetTimeout}{\param{int }{seconds}}
194
cf85cb95
GRG
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.
5a96d2f4
GL
199
200%
201% Notify
202%
d7cb14ce 203\membersection{wxSocketBase::Notify}\label{wxsocketbasenotify}
5a96d2f4
GL
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
e79848ac
GL
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
cf85cb95
GRG
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.
e79848ac
GL
229
230\membersection{wxSocketBase::IsConnected}\label{wxsocketbaseconnected}
231
232\constfunc{bool}{IsConnected}{\void}
233
234Returns TRUE if the socket is connected.
235
42ff6409 236\membersection{wxSocketBase::IsData}\label{wxsocketbaseisdata}
e79848ac
GL
237
238\constfunc{bool}{IsData}{\void}
239
cf85cb95 240Returns TRUE if there is data available to be read.
e79848ac
GL
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
aa6d9706 256\constfunc{wxUint32}{LastCount}{\void}
e79848ac
GL
257
258Returns the number of bytes read or written by the last IO call.
259
cf85cb95
GRG
260The following operations update the LastCount() value:
261Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
262
e79848ac
GL
263\membersection{wxSocketBase::LastError}\label{wxsocketbaselasterror}
264
aa6d9706 265\constfunc{wxSocketError}{LastError}{\void}
e79848ac 266
cf85cb95
GRG
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.
e79848ac
GL
275
276% ---------------------------------------------------------------------------
277% IO calls
278% ---------------------------------------------------------------------------
e79848ac
GL
279%
280% Peek
281%
e79848ac
GL
282\membersection{wxSocketBase::Peek}\label{wxsocketbasepeek}
283
aa6d9706 284\func{wxSocketBase\&}{Peek}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac
GL
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
cf85cb95
GRG
289Use LastCount to verify the number of bytes actually peeked.
290
291Use Error to determine if the operation succeeded.
292
e79848ac
GL
293\wxheading{Parameters}
294
295\docparam{buffer}{Buffer where to put peeked data.}
42ff6409 296
e79848ac
GL
297\docparam{nbytes}{Number of bytes.}
298
42ff6409
JS
299\wxheading{Return value}
300
e79848ac
GL
301Returns a reference to the current object.
302
cf85cb95
GRG
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
e79848ac
GL
308\wxheading{See also}
309
407f3681
JS
310\helpref{wxSocketBase::Error}{wxsocketbaseerror},
311\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
312\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
cf85cb95 313\helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
e79848ac
GL
314
315%
316% Read
317%
e79848ac
GL
318\membersection{wxSocketBase::Read}\label{wxsocketbaseread}
319
aa6d9706 320\func{wxSocketBase\&}{Read}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac
GL
321
322This function reads a buffer of {\it nbytes} bytes from the socket.
323
cf85cb95
GRG
324Use LastCount to verify the number of bytes actually read.
325
326Use Error to determine if the operation succeeded.
327
e79848ac
GL
328\wxheading{Parameters}
329
330\docparam{buffer}{Buffer where to put read data.}
42ff6409 331
e79848ac
GL
332\docparam{nbytes}{Number of bytes.}
333
42ff6409
JS
334\wxheading{Return value}
335
e79848ac
GL
336Returns a reference to the current object.
337
9f3430a6
GL
338\wxheading{Remark/Warning}
339
cf85cb95 340The exact behaviour of wxSocketBase::Read() depends on the combination
407f3681 341of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}.
9f3430a6 342
e79848ac
GL
343\wxheading{See also}
344
407f3681
JS
345\helpref{wxSocketBase::Error}{wxsocketbaseerror},
346\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
347\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
cf85cb95 348\helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
42ff6409 349
e79848ac 350%
5a96d2f4 351% Write
e79848ac 352%
e79848ac
GL
353\membersection{wxSocketBase::Write}\label{wxsocketbasewrite}
354
aa6d9706 355\func{wxSocketBase\&}{Write}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac 356
cf85cb95 357This function writes a buffer of {\it nbytes} bytes to the socket.
e79848ac 358
cf85cb95 359Use LastCount to verify the number of bytes actually written.
9f3430a6 360
cf85cb95 361Use Error to determine if the operation succeeded.
9f3430a6 362
e79848ac
GL
363\wxheading{Parameters}
364
cf85cb95 365\docparam{buffer}{Buffer with the data to be sent.}
42ff6409 366
e79848ac
GL
367\docparam{nbytes}{Number of bytes.}
368
42ff6409
JS
369\wxheading{Return value}
370
e79848ac
GL
371Returns a reference to the current object.
372
cf85cb95
GRG
373\wxheading{Remark/Warning}
374
375The exact behaviour of wxSocketBase::Write() depends on the combination
407f3681 376of flags being used. For a detailed explanation, see \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}.
cf85cb95 377
e79848ac
GL
378\wxheading{See also}
379
407f3681
JS
380\helpref{wxSocketBase::Error}{wxsocketbaseerror},
381\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
382\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
cf85cb95 383\helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags}
e79848ac
GL
384
385%
386% WriteMsg
387%
e79848ac
GL
388\membersection{wxSocketBase::WriteMsg}\label{wxsocketbasewritemsg}
389
aa6d9706 390\func{wxSocketBase\&}{WriteMsg}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac 391
cf85cb95 392This function writes a buffer of {\it nbytes} bytes from the socket, but it
e79848ac 393writes a short header before so that ReadMsg can alloc the right size for
cf85cb95
GRG
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.
e79848ac
GL
401
402\wxheading{Parameters}
403
cf85cb95 404\docparam{buffer}{Buffer with the data to be sent.}
42ff6409 405
e79848ac
GL
406\docparam{nbytes}{Number of bytes.}
407
42ff6409
JS
408\wxheading{Return value}
409
e79848ac
GL
410Returns a reference to the current object.
411
cf85cb95
GRG
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
e79848ac
GL
418\wxheading{See also}
419
407f3681
JS
420\helpref{wxSocketBase::Error}{wxsocketbaseerror},
421\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
422\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
423\helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags},
9f3430a6 424\helpref{wxSocketBase::ReadMsg}{wxsocketbasereadmsg}
e79848ac
GL
425
426%
427% ReadMsg
428%
e79848ac
GL
429\membersection{wxSocketBase::ReadMsg}\label{wxsocketbasereadmsg}
430
aa6d9706 431\func{wxSocketBase\&}{ReadMsg}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac
GL
432
433This function reads a buffer sent by WriteMsg on a socket. If the buffer passed
cf85cb95
GRG
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.
e79848ac
GL
440
441\wxheading{Parameters}
442
443\docparam{buffer}{Buffer where to put read data.}
42ff6409 444
e79848ac
GL
445\docparam{nbytes}{Number of bytes allocated for the buffer.}
446
42ff6409
JS
447\wxheading{Return value}
448
e79848ac
GL
449Returns a reference to the current object.
450
cf85cb95
GRG
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
e79848ac
GL
457\wxheading{See also}
458
407f3681
JS
459\helpref{wxSocketBase::Error}{wxsocketbaseerror},
460\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
461\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
462\helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags},
9f3430a6 463\helpref{wxSocketBase::WriteMsg}{wxsocketbasewritemsg}
e79848ac
GL
464
465%
466% Unread
467%
09eea162 468\membersection{wxSocketBase::Unread}\label{wxsocketbaseunread}
e79848ac 469
aa6d9706 470\func{wxSocketBase\&}{Unread}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
e79848ac 471
cf85cb95
GRG
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.
e79848ac
GL
478
479\wxheading{Parameters}
480
481\docparam{buffer}{Buffer to be unread.}
42ff6409 482
e79848ac
GL
483\docparam{nbytes}{Number of bytes.}
484
42ff6409
JS
485\wxheading{Return value}
486
e79848ac
GL
487Returns a reference to the current object.
488
489\wxheading{See also}
490
407f3681
JS
491\helpref{wxSocketBase::Error}{wxsocketbaseerror},
492\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
9f3430a6 493\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
e79848ac
GL
494
495%
496% Discard
497%
e79848ac
GL
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
407f3681
JS
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.
cf85cb95
GRG
505
506Use LastCount to see the number of bytes discarded.
507
508If you use Error, it will always return FALSE.
e79848ac
GL
509
510% ---------------------------------------------------------------------------
511% Wait functions
512% ---------------------------------------------------------------------------
513\membersection{wxSocketBase::Wait}\label{wxsocketbasewait}
42ff6409 514
aa6d9706 515\func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
e79848ac 516
cf85cb95
GRG
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).
e79848ac
GL
521
522\wxheading{Parameters}
523
cf85cb95 524\docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
42ff6409 525
aa6d9706 526\docparam{millisecond}{Number of milliseconds to wait.}
e79848ac 527
42ff6409 528\wxheading{Return value}
e79848ac
GL
529
530Returns TRUE if an event occured, FALSE if the timeout was reached.
531
532\wxheading{See also}
533
407f3681
JS
534\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
535\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
9f3430a6 536\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
e79848ac
GL
537
538%
539% WaitForRead
540%
e79848ac 541\membersection{wxSocketBase::WaitForRead}\label{wxsocketbasewaitforread}
42ff6409 542
aa6d9706 543\func{bool}{WaitForRead}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
e79848ac 544
cf85cb95 545This function waits until there is data available to be read.
e79848ac
GL
546
547\wxheading{Parameters}
548
cf85cb95 549\docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
42ff6409 550
aa6d9706 551\docparam{millisecond}{Number of milliseconds to wait.}
e79848ac 552
42ff6409 553\wxheading{Return value}
e79848ac 554
cf85cb95 555Returns TRUE if there is data to be read, FALSE if the timeout was reached.
e79848ac
GL
556
557\wxheading{See also}
558
407f3681
JS
559\helpref{wxSocketBase::Wait}{wxsocketbasewait},
560\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
9f3430a6 561\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
e79848ac
GL
562
563%
564% WaitForWrite
565%
e79848ac 566\membersection{wxSocketBase::WaitForWrite}\label{wxsocketbasewaitforwrite}
42ff6409 567
aa6d9706 568\func{bool}{WaitForWrite}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
e79848ac 569
cf85cb95 570This function waits until you can write to the socket.
e79848ac
GL
571
572\wxheading{Parameters}
573
cf85cb95 574\docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
42ff6409 575
aa6d9706 576\docparam{millisecond}{Number of milliseconds to wait.}
e79848ac 577
42ff6409 578\wxheading{Return value}
e79848ac 579
cf85cb95 580Returns TRUE if you can write to the socket, FALSE if the timeout was reached.
e79848ac
GL
581
582\wxheading{See also}
583
407f3681
JS
584\helpref{wxSocketBase::Wait}{wxsocketbasewait},
585\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
9f3430a6 586\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
e79848ac
GL
587
588%
589% WaitForLost
590%
e79848ac 591\membersection{wxSocketBase::WaitForLost}\label{wxsocketbasewaitforlost}
42ff6409 592
aa6d9706 593\func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
e79848ac 594
cf85cb95
GRG
595This function waits until the connection is lost. This may happen if the
596peer closes the connection or if the connection breaks.
e79848ac
GL
597
598\wxheading{Parameters}
599
cf85cb95 600\docparam{seconds}{Number of seconds to wait. If -1, it will wait for the default timeout set with SetTimeout.}
42ff6409 601
aa6d9706 602\docparam{millisecond}{Number of milliseconds to wait.}
e79848ac 603
42ff6409 604\wxheading{Return value}
e79848ac 605
cf85cb95 606Returns TRUE if the connection was lost, FALSE if the timeout was reached.
e79848ac
GL
607
608\wxheading{See also}
609
407f3681
JS
610\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
611\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
9f3430a6 612\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
42ff6409 613
cf85cb95
GRG
614% ---------------------------------------------------------------------------
615% Socket state
616% ---------------------------------------------------------------------------
617
42ff6409
JS
618%
619% RestoreState
620%
621\membersection{wxSocketBase::RestoreState}\label{wxsocketbaserestorestate}
622
623\func{void}{RestoreState}{\void}
624
cf85cb95
GRG
625This function restores the previous state of the socket, as saved
626with SaveState.
627
628Calls to SaveState / RestoreState can be nested.
42ff6409
JS
629
630\wxheading{See also}
631
632\helpref{wxSocketBase::SaveState}{wxsocketbasesavestate}
e79848ac 633
e79848ac
GL
634%
635% SaveState
636%
637\membersection{wxSocketBase::SaveState}\label{wxsocketbasesavestate}
42ff6409 638
e79848ac
GL
639\func{void}{SaveState}{\void}
640
641This function saves the current state of the socket object in a stack:
cf85cb95
GRG
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.
e79848ac
GL
646
647\wxheading{See also}
648
649\helpref{wxSocketBase::RestoreState}{wxsocketbaserestorestate}
aa6d9706
GL
650
651%
652% GetLocal
653%
654\membersection{wxSocketBase::GetLocal}{wxsocketbasegetlocal}
7e9a386e 655
aa6d9706
GL
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}
7e9a386e 670
aa6d9706
GL
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.
e79848ac 680
e79848ac
GL
681% ---------------------------------------------------------------------------
682% Socket callbacks
683% ---------------------------------------------------------------------------
42ff6409 684\membersection{wxSocketBase::SetEventHandler}\label{wxsocketbaseseteventhandler}
e79848ac 685
e79848ac
GL
686\func{void}{SetEventHandler}{\param{wxEvtHandler\&}{ evt\_hdlr}, \param{int}{ id = -1}}
687
cf85cb95
GRG
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.
e79848ac
GL
694
695\wxheading{Parameters}
696
697\docparam{evt\_hdlr}{Specifies the event handler you want to use.}
42ff6409 698
e79848ac
GL
699\docparam{id}{The id of socket event.}
700
701\wxheading{See also}
702
407f3681
JS
703\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
704\helpref{wxSocketBase::Notify}{wxsocketbasenotify},
705\helpref{wxSocketEvent}{wxsocketevent},
706\helpref{wxEvtHandler}{wxevthandler},
707\helpref{wxSocketBase::Callback}{wxsocketbasecallback},
cf85cb95 708\helpref{wxSocketBase::CallbackData}{wxsocketbasecallbackdata}
aa6d9706
GL
709
710\membersection{wxSocketBase::Callback}\label{wxsocketbasecallback}
711
712\func{wxSocketBase::wxSockCbk}{Callback}{\param{wxSocketBase::wxSockCbk}{ callback}}
713
cf85cb95
GRG
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
aa6d9706
GL
718\begin{verbatim}
719void SocketCallback(wxSocketBase& sock,wxSocketNotify evt,char *cdata);
720\end{verbatim}
721
cf85cb95
GRG
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}).
1fb3eae5 724The third parameter is the user data you specified using \helpref{CallbackData}{wxsocketbasecallbackdata}.
aa6d9706
GL
725
726\wxheading{Return value}
727
cf85cb95 728A pointer to the previous callback.
aa6d9706
GL
729
730\wxheading{See also}
731
407f3681
JS
732\helpref{wxSocketBase::CallbackData}{wxsocketbasecallbackdata},
733\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
aa6d9706
GL
734\helpref{wxSocketBase::Notify}{wxsocketbasenotify}
735
cf85cb95 736\membersection{wxSocketBase::CallbackData}\label{wxsocketbasecallbackdata}
aa6d9706
GL
737
738\func{char *}{CallbackData}{\param{char *}{cdata}}
739
cf85cb95 740This function sets the the user data which will be passed to a \helpref{C callback}{wxsocketbasecallback}.
aa6d9706
GL
741
742\wxheading{Return value}
743
cf85cb95
GRG
744A pointer to the previous user data.
745
407f3681
JS
746\helpref{wxSocketBase::Callback}{wxsocketbasecallback},
747\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
cf85cb95 748\helpref{wxSocketBase::Notify}{wxsocketbasenotify}
e79848ac
GL
749
750% ---------------------------------------------------------------------------
751% CLASS wxSocketClient
752% ---------------------------------------------------------------------------
e79848ac
GL
753\section{\class{wxSocketClient}}\label{wxsocketclient}
754
755\wxheading{Derived from}
756
757\helpref{wxSocketBase}{wxsocketbase}
758
954b8ae6
JS
759\wxheading{Include files}
760
761<wx/socket.h>
762
e79848ac
GL
763% ---------------------------------------------------------------------------
764% Members
765% ---------------------------------------------------------------------------
e79848ac
GL
766%
767% wxSocketClient
768%
e79848ac 769\membersection{wxSocketClient::wxSocketClient}
42ff6409 770
e79848ac
GL
771\func{}{wxSocketClient}{\param{wxSockFlags}{ flags = wxSocketBase::NONE}}
772
773Constructs a new wxSocketClient.
42ff6409 774
e79848ac
GL
775\wxheading{Parameters}
776
777\docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})}
778
779%
780% ~wxSocketClient
781%
e79848ac 782\membersection{wxSocketClient::\destruct{wxSocketClient}}
42ff6409 783
e79848ac
GL
784\func{}{\destruct{wxSocketClient}}{\void}
785
aed0ed3c 786Destroys a wxSocketClient object.
e79848ac
GL
787
788%
789% Connect
790%
42ff6409 791\membersection{wxSocketClient::Connect}\label{wxsocketclientconnect}
e79848ac 792
e79848ac
GL
793\func{bool}{Connect}{\param{wxSockAddress\&}{ address}, \param{bool}{ wait = TRUE}}
794
cf85cb95
GRG
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.
407f3681 799
cf85cb95
GRG
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
407f3681 806succesful establishment) and "lost" events (for connection failure).
e79848ac
GL
807
808\wxheading{Parameters}
809
810\docparam{address}{Address of the server.}
42ff6409 811
e79848ac
GL
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
cf85cb95
GRG
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
e79848ac
GL
825\wxheading{See also}
826
407f3681
JS
827\helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect},
828\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
cf85cb95 829\helpref{wxSocketBase::Notify}{wxsocketbasenotify}
e79848ac
GL
830
831%
832% WaitOnConnect
833%
42ff6409 834\membersection{wxSocketClient::WaitOnConnect}\label{wxsocketclientwaitonconnect}
e79848ac 835
aa6d9706 836\func{bool}{WaitOnConnect}{\param{long}{ seconds = -1}, \param{long}{ milliseconds = 0}}
e79848ac 837
cf85cb95
GRG
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.
e79848ac
GL
852
853\wxheading{See also}
854
cf85cb95 855\helpref{wxSocketClient::Connect}{wxsocketclientconnect}
e79848ac
GL
856
857% ---------------------------------------------------------------------------
42ff6409 858% CLASS: wxSocketEvent
e79848ac 859% ---------------------------------------------------------------------------
42ff6409 860\section{\class{wxSocketEvent}}\label{wxsocketevent}
e79848ac 861
42ff6409 862This event class contains information about socket events.
e79848ac
GL
863
864\wxheading{Derived from}
865
42ff6409 866\helpref{wxEvent}{wxevent}
e79848ac 867
954b8ae6
JS
868\wxheading{Include files}
869
870<wx/socket.h>
871
42ff6409 872\wxheading{Event table macros}
e79848ac 873
42ff6409
JS
874To process a socket event, use these event handler macros to direct input to member
875functions that take a wxSocketEvent argument.
e79848ac 876
42ff6409
JS
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}%
e79848ac 881
cf85cb95
GRG
882[TODO:]
883A brief note on how to use events.
884The wxSOCKET_INPUT event is generated when the
885
e79848ac
GL
886\wxheading{See also}
887
407f3681
JS
888\helpref{wxSocketBase}{wxsocketbase},
889\helpref{wxSocketClient}{wxsocketclient},
42ff6409 890\helpref{wxSocketServer}{wxsocketserver}
e79848ac 891
42ff6409 892\latexignore{\rtfignore{\wxheading{Members}}}
e79848ac 893
42ff6409 894\membersection{wxSocketEvent::wxSocketEvent}
e79848ac 895
42ff6409 896\func{}{wxSocketEvent}{\param{int}{ id = 0}}
e79848ac 897
42ff6409 898Constructor.
e79848ac 899
42ff6409 900\membersection{wxSocketEvent::SocketEvent}\label{wxsocketeventsocketevent}
e79848ac 901
aa6d9706 902\constfunc{wxSocketNotify}{SocketEvent}{\void}
e79848ac 903
42ff6409 904Returns the socket event type.
e79848ac 905
42ff6409
JS
906% ---------------------------------------------------------------------------
907% CLASS: wxSocketServer
908% ---------------------------------------------------------------------------
909\section{\class{wxSocketServer}}\label{wxsocketserver}
910
911\wxheading{Derived from}
912
913\helpref{wxSocketBase}{wxsocketbase}
914
954b8ae6
JS
915\wxheading{Include files}
916
917<wx/socket.h>
918
42ff6409
JS
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
42ff6409
JS
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
cf85cb95 946Destroys a wxSocketServer object (it doesn't close the accepted connections).
42ff6409
JS
947
948%
949% Accept
950%
1fb3eae5 951\membersection{wxSocketServer::Accept}\label{wxsocketserveraccept}
42ff6409 952
cf85cb95
GRG
953\func{wxSocketBase *}{Accept}{\param{bool}{ wait = TRUE}}
954
955Creates a new object wxSocketBase and accepts an incoming connection.
42ff6409 956
cf85cb95
GRG
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.
42ff6409
JS
967
968\wxheading{Return value}
969
cf85cb95
GRG
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.
42ff6409
JS
973
974\wxheading{See also}
975
1fb3eae5 976\helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept},
407f3681
JS
977\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
978\helpref{wxSocketBase::Notify}{wxsocketbasenotify},
42ff6409
JS
979\helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
980
981%
982% AcceptWith
983%
984\membersection{wxSocketServer::AcceptWith}\label{wxsocketserveracceptwith}
985
cf85cb95 986\func{bool}{AcceptWith}{\param{wxSocketBase\&}{ socket}, \param{bool}{ wait = TRUE}}
42ff6409
JS
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
cf85cb95
GRG
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
1fb3eae5 1001\helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept},
407f3681
JS
1002\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify},
1003\helpref{wxSocketBase::Notify}{wxsocketbasenotify},
1004\helpref{wxSocketServer::Accept}{wxsocketserveraccept}
cf85cb95
GRG
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
407f3681 1029\helpref{wxSocketServer::Accept}{wxsocketserveraccept},
cf85cb95
GRG
1030\helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
1031