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