]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/socket.tex
* Fixed a bug in notebook.tex
[wxWidgets.git] / docs / latex / wx / socket.tex
CommitLineData
e79848ac
GL
1\section{\class{wxSocketBase}}\label{wxsocketbase}
2
3\wxheading{Derived from}
4
5\helpref{wxEvtHandler}{wxevthandler}
6
7% ---------------------------------------------------------------------------
8% Event handling
9% ---------------------------------------------------------------------------
10\wxheading{Event handling}
11
12To process events from a socket, use the following event handler macro to direct
13 input to member
14functions that take a \helpref{wxSocketEvent}{wxsocketevent} argument.
15
16\twocolwidtha{7cm}
17\begin{twocollist}\itemsep=0pt
18\twocolitem{{\bf EVT\_SOCKET(id, func)}}{A socket event occured.}
19\end{twocollist}%
20
21% ---------------------------------------------------------------------------
22% See also ...
23% ---------------------------------------------------------------------------
24
25\wxheading{See also}
26
27\helpref{wxSocketEvent}{wxsocketevent}
28\helpref{wxSocketClient}{wxsocketclient}
29\helpref{wxSocketServer}{wxsocketserver}
30
31% ---------------------------------------------------------------------------
32% Members
33% ---------------------------------------------------------------------------
34
35\latexignore{\rtfignore{\wxheading{Members}}}
36
37\membersection{wxSocketBase::wxSocketBase}
38\func{}{wxSocketBase}{\void}
39
40Default constructor but don't use it, you must use \helpref{wxSocketClient}{wxsocketclient}
41or \helpref{wxSocketServer}{wxsocketserver}.
42
43\membersection{wxSocketBase::\destruct{wxSocketBase}}
44
45\func{}{\destruct{wxSocketBase}}{\void}
46
47Destroys the wxSocketBase object.
48
49% ---------------------------------------------------------------------------
50% State functions
51% ---------------------------------------------------------------------------
52
53\membersection{wxSocketBase::Ok}\label{wxsocketbaseok}
54
55\constfunc{bool}{Ok}{\void}
56
57Returns TRUE if the socket is initialized and ready and FALSE in other
58cases.
59
60\membersection{wxSocketBase::Error}\label{wxsocketbaseerror}
61
62\constfunc{bool}{Error}{\void}
63
64Returns TRUE if an error occured.
65
66\membersection{wxSocketBase::IsConnected}\label{wxsocketbaseconnected}
67
68\constfunc{bool}{IsConnected}{\void}
69
70Returns TRUE if the socket is connected.
71
72\membersection{wxSocketBase::IsData}\label{wxsocketbaseerror}
73
74\constfunc{bool}{IsData}{\void}
75
76Returns TRUE if some data is arrived on the socket.
77
78\membersection{wxSocketBase::IsDisconnected}\label{wxsocketbasedisconnected}
79
80\constfunc{bool}{IsDisconnected}{\void}
81
82Returns TRUE if the socket is disconnected.
83
84\membersection{wxSocketBase::IsNoWait}\label{wxsocketbasenowait}
85
86\constfunc{bool}{IsNoWait}{\void}
87
88Returns TRUE if the socket mustn't wait.
89
90\membersection{wxSocketBase::LastCount}\label{wxsocketbaselastcount}
91
92\constfunc{size\_t}{LastCount}{\void}
93
94Returns the number of bytes read or written by the last IO call.
95
96\membersection{wxSocketBase::LastError}\label{wxsocketbaselasterror}
97
98\constfunc{int}{LastError}{\void}
99
100Returns an error in the errno format (see your C programmer's guide).
101
102% ---------------------------------------------------------------------------
103% IO calls
104% ---------------------------------------------------------------------------
105
106%
107% Peek
108%
109
110\membersection{wxSocketBase::Peek}\label{wxsocketbasepeek}
111
112\func{wxSocketBase\&}{Peek}{\param{char *}{ buffer}, \param{size\_t}{ nbytes}}
113
114This function peeks a buffer of {\it nbytes} bytes from the socket. Peeking a buffer
115doesn't delete it from the system socket in-queue.
116
117\wxheading{Parameters}
118
119\docparam{buffer}{Buffer where to put peeked data.}
120\docparam{nbytes}{Number of bytes.}
121
122\wxheading{Returns value}
123Returns a reference to the current object.
124
125\wxheading{See also}
126
127\helpref{wxSocketBase::Error}{wxsocketbaserror},
128\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
129\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
130
131%
132% Read
133%
134
135\membersection{wxSocketBase::Read}\label{wxsocketbaseread}
136
137\func{wxSocketBase\&}{Read}{\param{char *}{ buffer}, \param{size\_t}{ nbytes}}
138
139This function reads a buffer of {\it nbytes} bytes from the socket.
140
141\wxheading{Parameters}
142
143\docparam{buffer}{Buffer where to put read data.}
144\docparam{nbytes}{Number of bytes.}
145
146\wxheading{Returns value}
147Returns a reference to the current object.
148
149\wxheading{See also}
150
151\helpref{wxSocketBase::Error}{wxsocketbaserror},
152\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
153\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
154
155%
156% Read
157%
158
159\membersection{wxSocketBase::Write}\label{wxsocketbasewrite}
160
161\func{wxSocketBase\&}{Write}{\param{const char *}{ buffer}, \param{size\_t}{ nbytes}}
162
163This function writes a buffer of {\it nbytes} bytes from the socket.
164
165\wxheading{Parameters}
166
167\docparam{buffer}{Buffer where to get the data to write.}
168\docparam{nbytes}{Number of bytes.}
169
170\wxheading{Returns value}
171Returns a reference to the current object.
172
173\wxheading{See also}
174
175\helpref{wxSocketBase::Error}{wxsocketbaserror},
176\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
177\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
178
179%
180% WriteMsg
181%
182
183\membersection{wxSocketBase::WriteMsg}\label{wxsocketbasewritemsg}
184
185\func{wxSocketBase\&}{WriteMsg}{\param{const char *}{ buffer}, \param{size\_t}{ nbytes}}
186
187This function writes a buffer of {\it nbytes} bytes from the socket. But it
188writes a short header before so that ReadMsg can alloc the right size for
189the buffer. So a buffer sent with WriteMsg {\bf must} be read with ReadMsg.
190
191\wxheading{Parameters}
192
193\docparam{buffer}{Buffer where to put data peeked.}
194\docparam{nbytes}{Number of bytes.}
195
196\wxheading{Returns value}
197Returns a reference to the current object.
198
199\wxheading{See also}
200
201\helpref{wxSocketBase::Error}{wxsocketbaserror},
202\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
203\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
204\helpref{wxSocketBase::ReadMsg}{wxsocketbasereadmsg}
205
206%
207% ReadMsg
208%
209
210\membersection{wxSocketBase::ReadMsg}\label{wxsocketbasereadmsg}
211
212\func{wxSocketBase\&}{ReadMsg}{\param{char *}{ buffer}, \param{size\_t}{ nbytes}}
213
214This function reads a buffer sent by WriteMsg on a socket. If the buffer passed
215to the function isn't big enough, the function filled it and then discard the
216bytes left. This function always wait for the buffer to be entirely filled.
217
218\wxheading{Parameters}
219
220\docparam{buffer}{Buffer where to put read data.}
221\docparam{nbytes}{Number of bytes allocated for the buffer.}
222
223\wxheading{Returns value}
224Returns a reference to the current object.
225
226\wxheading{See also}
227
228\helpref{wxSocketBase::Error}{wxsocketbaserror},
229\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
230\helpref{wxSocketBase::LastError}{wxsocketbaselasterror},
231\helpref{wxSocketBase::WriteMsg}{wxsocketbasewritemsg}
232
233%
234% Unread
235%
236
237\membersection{wxSocketBase::UnRead}\label{wxsocketbaseunread}
238
239\func{wxSocketBase\&}{UnRead}{\param{const char *}{ buffer}, \param{size\_t}{ nbytes}}
240
241This function unreads a buffer. It means that the buffer is put in the top
242of the incoming queue. But, it is put also at the end of all unread buffers.
243It is useful for sockets because we can't seek it.
244
245\wxheading{Parameters}
246
247\docparam{buffer}{Buffer to be unread.}
248\docparam{nbytes}{Number of bytes.}
249
250\wxheading{Returns value}
251Returns a reference to the current object.
252
253\wxheading{See also}
254
255\helpref{wxSocketBase::Error}{wxsocketbaserror},
256\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
257\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
258
259%
260% Discard
261%
262
263\membersection{wxSocketBase::Discard}\label{wxsocketbasediscard}
264
265\func{wxSocketBase\&}{Discard}{\void}
266
267This function simply deletes all bytes in the incoming queue. This function
268doesn't wait.
269
270% ---------------------------------------------------------------------------
271% Wait functions
272% ---------------------------------------------------------------------------
273\membersection{wxSocketBase::Wait}\label{wxsocketbasewait}
274\func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ microsecond = 0}}
275
276This function waits for an event: it could be an incoming byte, the possibility
277for the client to write, a lost connection, an incoming connection, an
278established connection.
279
280\wxheading{Parameters}
281
282\docparam{seconds}{Number of seconds to wait. By default, it waits infinitely.}
283\docparam{microsecond}{Number of microseconds to wait.}
284
285\wxheading{Return value:}
286
287Returns TRUE if an event occured, FALSE if the timeout was reached.
288
289\wxheading{See also}
290
291\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
292\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
293\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
294
295%
296% WaitForRead
297%
298
299\membersection{wxSocketBase::WaitForRead}\label{wxsocketbasewaitforread}
300\func{bool}{WaitForRead}{\param{long}{ seconds = -1}, \param{long}{ microsecond = 0}}
301
302This function waits for a read event.
303
304\wxheading{Parameters}
305
306\docparam{seconds}{Number of seconds to wait. By default, it waits infinitely.}
307\docparam{microsecond}{Number of microseconds to wait.}
308
309\wxheading{Return value:}
310
311Returns TRUE if a byte arrived, FALSE if the timeout was reached.
312
313\wxheading{See also}
314
315\helpref{wxSocketBase::Wait}{wxsocketbasewait},
316\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
317\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
318
319%
320% WaitForWrite
321%
322
323\membersection{wxSocketBase::WaitForWrite}\label{wxsocketbasewaitforwrite}
324\func{bool}{WaitForWrite}{\param{long}{ seconds = -1}, \param{long}{ microsecond = 0}}
325
326This function waits for a write event.
327
328\wxheading{Parameters}
329
330\docparam{seconds}{Number of seconds to wait. By default, it waits infinitely.}
331\docparam{microsecond}{Number of microseconds to wait.}
332
333\wxheading{Return value:}
334
335Returns TRUE if a write event occured, FALSE if the timeout was reached.
336
337\wxheading{See also}
338
339\helpref{wxSocketBase::Wait}{wxsocketbasewait},
340\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
341\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
342
343%
344% WaitForLost
345%
346
347\membersection{wxSocketBase::WaitForLost}\label{wxsocketbasewaitforlost}
348\func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ microsecond = 0}}
349
350This function waits for a "lost" event. For instance, the peer may have closed
351the connection, or the connection may have been broken.
352
353\wxheading{Parameters}
354
355\docparam{seconds}{Number of seconds to wait. By default, it waits infinitely.}
356\docparam{microsecond}{Number of microseconds to wait.}
357
358\wxheading{Return value:}
359
360Returns TRUE if a "lost" event occured, FALSE if the timeout was reached.
361
362\wxheading{See also}
363
364\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread},
365\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite},
366\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
367
368% ---------------------------------------------------------------------------
369% Socket state
370% ---------------------------------------------------------------------------
371
372%
373% SaveState
374%
375\membersection{wxSocketBase::SaveState}\label{wxsocketbasesavestate}
376\func{void}{SaveState}{\void}
377
378This function saves the current state of the socket object in a stack:
379actually it saves all flags and the state of the asynchronous callbacks.
380
381\wxheading{See also}
382
383\helpref{wxSocketBase::RestoreState}{wxsocketbaserestorestate}
384
385%
386% RestoreState
387%
388
389\membersection{wxSocketBase::RestoreState}\label{wxsocketbaserestorestate}
390
391\func{void}{RestoreState}{\void}
392
393This function restores a previously saved state.
394
395\wxheading{See also}
396
397\helpref{wxSocketBase::SaveState}{wxsocketbasesavestate}
398
399% ---------------------------------------------------------------------------
400% Socket callbacks
401% ---------------------------------------------------------------------------
402
403\membersection{wxSocketBase::SetEventHandler}{wxsocketbaseseteventhandler}
404\func{void}{SetEventHandler}{\param{wxEvtHandler\&}{ evt\_hdlr}, \param{int}{ id = -1}}
405
406Sets an event handler to be called when a socket event occured.
407
408\wxheading{Parameters}
409
410\docparam{evt\_hdlr}{Specifies the event handler you want to use.}
411\docparam{id}{The id of socket event.}
412
413\wxheading{See also}
414
415\helpref{wxSocketEvent}{wxsocketevent}
416
417% ---------------------------------------------------------------------------
418% CLASS wxSocketClient
419% ---------------------------------------------------------------------------
420
421\section{\class{wxSocketClient}}\label{wxsocketclient}
422
423\wxheading{Derived from}
424
425\helpref{wxSocketBase}{wxsocketbase}
426
427% ---------------------------------------------------------------------------
428% Members
429% ---------------------------------------------------------------------------
430
431%
432% wxSocketClient
433%
434
435\membersection{wxSocketClient::wxSocketClient}
436\func{}{wxSocketClient}{\param{wxSockFlags}{ flags = wxSocketBase::NONE}}
437
438Constructs a new wxSocketClient.
439{\bf Warning !} The created needs to be registered to a socket handler (See \helpref{wxSocketHandler}{wxsockethandler}).
440
441\wxheading{Parameters}
442
443\docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})}
444
445%
446% ~wxSocketClient
447%
448
449\membersection{wxSocketClient::\destruct{wxSocketClient}}
450\func{}{\destruct{wxSocketClient}}{\void}
451
452Destructs a wxSocketClient object.
453
454%
455% Connect
456%
457
458\membersection{wxSocketClient::Connect}{wxsocketclientconnect}
459\func{bool}{Connect}{\param{wxSockAddress\&}{ address}, \param{bool}{ wait = TRUE}}
460
461Connects to a server using the specified address. If {\it wait} is TRUE, Connect
462will wait for the socket ready to send or receive data.
463
464\wxheading{Parameters}
465
466\docparam{address}{Address of the server.}
467\docparam{wait}{If true, waits for the connection to be ready.}
468
469\wxheading{Return value}
470
471Returns TRUE if the connection is established and no error occurs.
472
473\wxheading{See also}
474
475\helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect}
476
477%
478% WaitOnConnect
479%
480
481\membersection{wxSocketClient::WaitOnConnect}
482\func{bool}{WaitOnConnect}{\param{long}{ seconds = -1}, \param{long}{ microseconds = 0}}
483
484Wait for a "connect" event.
485
486\wxheading{See also}
487
488\helpref{wxSocketBase::Wait}{wxsocketbasewait} for a detailed description.
489
490% ---------------------------------------------------------------------------
491% CLASS: wxSocketServer
492% ---------------------------------------------------------------------------
493
494\section{\class{wxSocketServer}}\label{wxsocketserver}
495
496\wxheading{Derived from}
497
498\helpref{wxSocketBase}{wxsocketbase}
499
500% ---------------------------------------------------------------------------
501% Members
502% ---------------------------------------------------------------------------
503
504\latexignore{\rtfignore{\wxheading{Members}}}
505
506%
507% wxSocketServer
508%
509
510\membersection{wxSocketServer::wxSocketServer}{wxsocketserverconstr}
511\func{}{wxSocketServer}{\param{wxSockAddress\&}{ address}, \param{wxSockFlags}{ flags = wxSocketBase::NONE}}
512
513Constructs a new wxSocketServer.
514{\bf Warning !} The created object needs to be registered to a socket handler
515(See \helpref{wxSocketHandler}{wxsockethandler}).
516
517\wxheading{Parameters}
518
519\docparam{address}{Specifies the local address for the server (e.g. port number).}
520\docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbase
521setflags})}
522
523%
524% ~wxSocketServer
525%
526
527\membersection{wxSocketServer::\destruct{wxSocketServer}}
528\func{}{\destruct{wxSocketServer}}{\void}
529
530Destructs a wxSocketServer object (it doesn't close the accepted connection).
531
532%
533% Accept
534%
535
536\membersection{wxSocketServer::Accept}
537\func{wxSocketBase *}{Accept}{\void}
538
539Creates a new object wxSocketBase and accepts an incoming connection. {\bf Warning !} This function will block the GUI.
540
541\wxheading{Return value}
542
543Returns an opened socket connection.
544
545\wxheading{See also}
546
547\helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
548
549%
550% AcceptWith
551%
552
553\membersection{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
554\func{bool}{AcceptWith}{\param{wxSocketBase\&}{ socket}}
555
556Accept an incoming connection using the specified socket object.
557This is useful when someone wants to inherit wxSocketBase.
558
559\wxheading{Parameters}
560
561\docparam{socket}{Socket to be initialized}
562
563\wxheading{Return value}
564
565Returns TRUE if no error occurs, else FALSE.
566
567
568% ---------------------------------------------------------------------------
569% CLASS: wxSocketHandler
570% ---------------------------------------------------------------------------
571
572\section{\class{wxSocketHandler}}\label{wxsockethandler}
573
574\wxheading{Derived from}
575
576\helpref{wxObject}{wxobject}
577
578% ---------------------------------------------------------------------------
579% Members
580% ---------------------------------------------------------------------------
581
582\latexignore{\rtfignore{\wxheading{Members}}}
583
584%
585% wxSocketHandler
586%
587\membersection{wxSocketHandler::wxSocketHandler}
588\func{}{wxSocketHandler}{\void}
589
590Constructs a new wxSocketHandler.
591It is advised to use \helpref{wxSocketHandler::Master}{wxsockethandlermaster}
592to get a socket handler. But creating a socket handler is useful to group
593many sockets.
594
595%
596% ~wxSocketHandler
597%
598
599\membersection{wxSocketHandler::\destruct{wxSocketHandler}}
600\func{}{\destruct{wxSocketHandler}}{\void}
601
602Destructs a wxSocketHandler object.
603
604%
605% Register
606%
607
608\membersection{wxSocketHandler::Register}
609\func{void}{Register}{\param{wxSocketBase *}{socket}}
610
611Register a socket: if it is already registered in this handler it will just
612return immediately.
613
614\wxheading{Parameters}
615
616\docparam{socket}{Socket to be registered.}
617
618%
619% UnRegister
620%
621
622\membersection{wxSocketHandler::UnRegister}
623\func{void}{UnRegister}{\param{wxSocketBase *}{socket}}
624
625UnRegister a socket: if it isn't registered in this handler it will just
626return.
627
628\wxheading{Parameters}
629
630\docparam{socket}{Socket to be unregistered.}
631
632%
633% Count
634%
635
636\membersection{wxSocketHandler::Count}
637\constfunc{unsigned long}{Count}{\void}
638
639Returns the number of sockets registered in the handler.
640
641\wxheading{Return value}
642
643Number of sockets registered.
644
645%
646% CreateServer
647%
648
649\membersection{wxSocketHandler::CreateServer}
650\func{wxSocketServer *}{CreateServer}{\param{wxSockAddress\&}{ address}, \param{wxSocketBase::wxSockFlags}{ flags = wxSocketbase::NONE}}
651
652Creates a new wxSocketServer object. The object is automatically registered
653to the current socket handler.
654For a detailed description of the parameters, see \helpref{wxSocketServer::wxSocketServer}{wxsocketserverconstr}.
655
656\wxheading{Return value}
657
658Returns a new socket server.
659
660%
661% CreateClient
662%
663
664\membersection{wxSocketHandler::CreateClient}
665\func{wxSocketServer *}{CreateClient}{\param{wxSocketBase::wxSockFlags}{ flags = wxSocketbase::NONE}}
666
667Creates a new wxSocketClient object. The object is automatically registered
668to the current socket handler.
669For a detailed description of the parameters, see \helpref{wxSocketClient::Connect}{wxsocketclientconnect}.
670
671\wxheading{Return value}
672
673Returns a new socket client.
674
675%
676% Master
677%
678
679\membersection{wxSocketHandler::Master}
680\func{static wxSocketHandler\&}{Master}{\void}
681
682Returns a default socket handler.