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