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