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