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