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