1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxSocket docs
4 %% Author: Guillermo Rodriguez Garcia <guille@iies.es>
8 %% Copyright: (c) wxWindows team
9 %% Licence: wxWindows licence
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxSocketBase
}}\label{wxsocketbase
}
14 wxSocketBase is the base class for all socket-related objects, and it
15 defines all basic IO functionality.
17 \wxheading{Derived from
}
19 \helpref{wxEvtHandler
}{wxevthandler
}
21 \wxheading{Include files
}
25 \wxheading{wxSocket errors
}
28 \begin{twocollist
}\itemsep=
0pt
29 \twocolitem{{\bf wxSOCKET
\_NOERROR}}{No error happened.
}
30 \twocolitem{{\bf wxSOCKET
\_INVOP}}{Invalid operation.
}
31 \twocolitem{{\bf wxSOCKET
\_IOERR}}{Input/Output error.
}
32 \twocolitem{{\bf wxSOCKET
\_INVADDR}}{Invalid address passed to wxSocket.
}
33 \twocolitem{{\bf wxSOCKET
\_INVSOCK}}{Invalid socket (uninitialized).
}
34 \twocolitem{{\bf wxSOCKET
\_NOHOST}}{No corresponding host.
}
35 \twocolitem{{\bf wxSOCKET
\_INVPORT}}{Invalid port.
}
36 \twocolitem{{\bf wxSOCKET
\_WOULDBLOCK}}{The socket is non-blocking and the operation would block.
}
37 \twocolitem{{\bf wxSOCKET
\_TIMEDOUT}}{The timeout for this operation expired.
}
38 \twocolitem{{\bf wxSOCKET
\_MEMERR}}{Memory exhausted.
}
41 \wxheading{wxSocket events
}
44 \begin{twocollist
}\itemsep=
0pt
45 \twocolitem{{\bf wxSOCKET
\_INPUT}}{There is data available for reading.
}
46 \twocolitem{{\bf wxSOCKET
\_OUTPUT}}{The socket is ready to be written to.
}
47 \twocolitem{{\bf wxSOCKET
\_CONNECTION}}{Incoming connection (server), or connection establishment (client).
}
48 \twocolitem{{\bf wxSOCKET
\_LOST}}{The connection has been closed.
}
51 A brief note on how to use these events:
53 The
{\bf wxSOCKET
\_INPUT} event will be issued whenever there is data
54 available for reading. This will be the case if the input queue was
55 empty and new data arrives, or if the application has read some data
56 yet there is still more data available. This means that the application
57 does not need to read all available data in response to a
58 {\bf wxSOCKET
\_INPUT} event, as more events will be produced as
61 The
{\bf wxSOCKET
\_OUTPUT} event is issued when a socket is first
62 connected with
\helpref{Connect
}{wxsocketclientconnect
} or accepted
63 with
\helpref{Accept
}{wxsocketserveraccept
}. After that, new
64 events will be generated only after an output operation fails
65 with
{\bf wxSOCKET
\_WOULDBLOCK} and buffer space becomes available
66 again. This means that the application should assume that it
67 can write data to the socket until an
{\bf wxSOCKET
\_WOULDBLOCK}
68 error occurs; after this, whenever the socket becomes writable
69 again the application will be notified with another
70 {\bf wxSOCKET
\_OUTPUT} event.
72 The
{\bf wxSOCKET
\_CONNECTION} event is issued when a delayed connection
73 request completes succesfully (client) or when a new connection arrives
74 at the incoming queue (server).
76 The
{\bf wxSOCKET
\_LOST} event is issued when a close indication is
77 received for the socket. This means that the connection broke down or
78 that it was closed by the peer. Also, this event will be issued if
79 a delayed connection request fails.
81 \wxheading{Event handling
}
83 To process events coming from a socket object, use the following event
84 handler macro to direct events to member functions that take a
85 \helpref{wxSocketEvent
}{wxsocketevent
} argument.
88 \begin{twocollist
}\itemsep=
0pt
89 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{Process a wxEVT
\_SOCKET event.
}
94 \helpref{wxSocketEvent
}{wxsocketevent
},
95 \helpref{wxSocketClient
}{wxsocketclient
},
96 \helpref{wxSocketServer
}{wxsocketserver
},
97 \helpref{Sockets sample
}{samplesockets
}
99 % ---------------------------------------------------------------------------
101 % ---------------------------------------------------------------------------
103 \latexignore{\rtfignore{\wxheading{Function groups
}}}
105 \membersection{Construction and destruction
}
107 \helpref{wxSocketBase
}{wxsocketbaseconstruct
}\\
108 \helpref{\destruct{wxSocketBase
}}{wxsocketbasedestruct
}
110 \membersection{Socket state
}
112 Functions to retrieve current state and miscellaneous info.
114 \helpref{Error
}{wxsocketbaseerror
}\\
115 \helpref{GetLocal
}{wxsocketbasegetlocal
}\\
116 \helpref{GetPeer
}{wxsocketbasegetpeer
}
117 \helpref{IsConnected
}{wxsocketbaseisconnected
}\\
118 \helpref{IsData
}{wxsocketbaseisdata
}\\
119 \helpref{IsDisconnected
}{wxsocketbaseisdisconnected
}\\
120 \helpref{LastCount
}{wxsocketbaselastcount
}\\
121 \helpref{LastError
}{wxsocketbaselasterror
}\\
122 \helpref{Ok
}{wxsocketbaseok
}\\
123 \helpref{SaveState
}{wxsocketbasesavestate
}\\
124 \helpref{RestoreState
}{wxsocketbaserestorestate
}
126 \membersection{Basic IO
}
128 Functions that perform basic IO functionality.
130 \helpref{Close
}{wxsocketbaseclose
}\\
131 \helpref{Discard
}{wxsocketbasediscard
}\\
132 \helpref{Peek
}{wxsocketbasepeek
}\\
133 \helpref{Read
}{wxsocketbaseread
}\\
134 \helpref{ReadMsg
}{wxsocketbasereadmsg
}\\
135 \helpref{Unread
}{wxsocketbaseunread
}\\
136 \helpref{Write
}{wxsocketbasewrite
}\\
137 \helpref{WriteMsg
}{wxsocketbasewritemsg
}
139 Functions that perform a timed wait on a certain IO condition.
141 \helpref{Wait
}{wxsocketbasewait
}\\
142 \helpref{WaitForRead
}{wxsocketbasewaitforread
}\\
143 \helpref{WaitForWrite
}{wxsocketbasewaitforwrite
}\\
144 \helpref{WaitForLost
}{wxsocketbasewaitforlost
}
146 Functions that allow applications to customize socket IO as needed.
148 \helpref{SetFlags
}{wxsocketbasesetflags
}\\
149 \helpref{SetTimeout
}{wxsocketbasesettimeout
}
151 \membersection{Handling socket events
}
153 Functions that allow applications to receive socket events.
155 \helpref{Notify
}{wxsocketbasenotify
}\\
156 \helpref{SetNotify
}{wxsocketbasesetnotify
}\\
157 \helpref{SetEventHandler
}{wxsocketbaseseteventhandler
}
159 Callback functions are also available, but they are provided for backwards
160 compatibility only. Their use is discouraged in favour of events, and should
161 be considered deprecated.
163 \helpref{Callback
}{wxsocketbasecallback
}\\
164 \helpref{CallbackData
}{wxsocketbasecallbackdata
}
167 % ---------------------------------------------------------------------------
169 % ---------------------------------------------------------------------------
171 \helponly{\insertatlevel{2}{
177 \membersection{wxSocketBase::wxSocketBase
}\label{wxsocketbaseconstruct
}
179 \func{}{wxSocketBase
}{\void}
181 Default constructor. Don't use it directly; instead, use
182 \helpref{wxSocketClient
}{wxsocketclient
} to construct a socket client, or
183 \helpref{wxSocketServer
}{wxsocketserver
} to construct a socket server.
185 \membersection{wxSocketBase::
\destruct{wxSocketBase
}}\label{wxsocketbasedestruct
}
187 \func{}{\destruct{wxSocketBase
}}{\void}
194 \membersection{wxSocketBase::Callback
}\label{wxsocketbasecallback
}
196 \func{wxSocketBase::wxSockCbk
}{Callback
}{\param{wxSocketBase::wxSockCbk
}{ callback
}}
198 You can setup a callback function to be called when an event occurs.
199 The function will be called only for those events for which notification
200 has been enabled with
\helpref{Notify
}{wxsocketbasenotify
} and
201 \helpref{SetNotify
}{wxsocketbasesetnotify
}. The prototype of the
202 callback must be as follows:
205 void SocketCallback(wxSocketBase& sock, wxSocketNotify evt, char *cdata);
208 The first parameter is a reference to the socket object in which the
209 event occured. The second parameter tells you which event occured.
210 (See
\helpref{wxSocket events
}{wxsocketbase
}). The third parameter
211 is the user data you specified using
212 \helpref{CallbackData
}{wxsocketbasecallbackdata
}.
214 Note that events are preferred over callbacks where possible.
216 \wxheading{Return value
}
218 A pointer to the previous callback.
222 \helpref{wxSocketBase::CallbackData
}{wxsocketbasecallbackdata
},
223 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
224 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
229 \membersection{wxSocketBase::CallbackData
}\label{wxsocketbasecallbackdata
}
231 \func{char *
}{CallbackData
}{\param{char *
}{cdata
}}
233 This function sets the the user data which will be passed to a
234 callback function set via
\helpref{Callback
}{wxsocketbasecallback
}.
236 Note that events are preferred over callbacks where possible.
238 \wxheading{Return value
}
240 A pointer to the previous user data.
242 \helpref{wxSocketBase::Callback
}{wxsocketbasecallback
},
243 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
244 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
249 \membersection{wxSocketBase::Close
}\label{wxsocketbaseclose
}
251 \func{void
}{Close
}{\void}
253 This function shuts down the socket, disabling further transmission and
254 reception of data; it also disables events for the socket and frees the
255 associated system resources. If you destroy a socket, Close is automatically
258 \wxheading{Remark/Warning
}
260 Although Close immediately disables events for the socket, it is possible
261 that event messages may be waiting in the application's event queue. The
262 application must therefore be prepared to handle socket event messages
263 even after calling Close.
268 \membersection{wxSocketBase::Discard
}\label{wxsocketbasediscard
}
270 \func{wxSocketBase\&
}{Discard
}{\void}
272 This function simply deletes all bytes in the incoming queue. This function
273 always returns immediately and its operation is not affected by IO flags.
275 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually discarded.
277 If you use
\helpref{Error
}{wxsocketbaseerror
}, it will always return FALSE.
282 \membersection{wxSocketBase::Error
}\label{wxsocketbaseerror
}
284 \constfunc{bool
}{Error
}{\void}
286 Returns TRUE if an error occured in the last IO operation.
288 Use this function to check for an error condition after one of the
289 following calls: Discard, Peek, Read, ReadMsg, Unread, Write, WriteMsg.
294 \membersection{wxSocketBase::GetLocal
}\label{wxsocketbasegetlocal
}
296 \constfunc{bool
}{GetLocal
}{\param{wxSockAddress\&
}{addr
\_man}}
298 This function returns the local address field of the socket. The local
299 address field contains the complete local address of the socket (local
300 address, local port, ...).
302 \wxheading{Return value
}
304 It returns TRUE if no errors happened, FALSE otherwise.
309 \membersection{wxSocketBase::GetPeer
}\label{wxsocketbasegetpeer
}
311 \constfunc{bool
}{GetPeer
}{\param{wxSockAddress\&
}{addr
\_man}}
313 This function returns the peer address field of the socket. The peer
314 address field contains the complete peer host address of the socket
315 (address, port, ...).
317 \wxheading{Return value
}
319 It returns TRUE if no errors happened, FALSE otherwise.
324 \membersection{wxSocketBase::IsConnected
}\label{wxsocketbaseisconnected
}
326 \constfunc{bool
}{IsConnected
}{\void}
328 Returns TRUE if the socket is connected.
333 \membersection{wxSocketBase::IsData
}\label{wxsocketbaseisdata
}
335 \constfunc{bool
}{IsData
}{\void}
337 Returns TRUE if the socket is readable. This might mean that
338 queued data is available for reading or, for streamed sockets, that
339 the connection has been closed, so that a
\helpref{Read
}{wxsocketbaseread
},
340 \helpref{ReadMsg
}{wxsocketbasereadmsg
} or
\helpref{Peek
}{wxsocketbasepeek
}
341 operation is guaranteed to complete immediately (unless the
342 {\bf wxSOCKET
\_WAITALL} flag is set).
344 \membersection{wxSocketBase::IsDisconnected
}\label{wxsocketbaseisdisconnected
}
349 \constfunc{bool
}{IsDisconnected
}{\void}
351 Returns TRUE if the socket is not connected.
353 \membersection{wxSocketBase::LastCount
}\label{wxsocketbaselastcount
}
358 \constfunc{wxUint32
}{LastCount
}{\void}
360 Returns the number of bytes read or written by the last IO call.
362 Use this function to get the number of bytes actually transferred
363 after using one of the following IO calls: Discard, Peek, Read,
364 ReadMsg, Unread, Write, WriteMsg.
369 \membersection{wxSocketBase::LastError
}\label{wxsocketbaselasterror
}
371 \constfunc{wxSocketError
}{LastError
}{\void}
373 Returns the last wxSocket error. See
\helpref{wxSocket errors
}{wxsocketbase
}.
375 Please note that this function merely returns the last error code,
376 but it should not be used to determine if an error has occured (this
377 is because successful operations do not change the LastError value).
378 Use
\helpref{Error
}{wxsocketbaseerror
} first, in order to determine
379 if the last IO call failed. If this returns TRUE, use LastError
380 to discover the cause of the error.
385 \membersection{wxSocketBase::Notify
}\label{wxsocketbasenotify
}
387 \func{void
}{Notify
}{\param{bool
}{ notify
}}
389 According to the
{\it notify
} value, this function enables
390 or disables socket events. If
{\it notify
} is TRUE, the events
391 configured with
\helpref{SetNotify
}{wxsocketbasesetnotify
} will
392 be sent to the application. If
{\it notify
} is FALSE; no events
398 \membersection{wxSocketBase::Ok
}\label{wxsocketbaseok
}
400 \constfunc{bool
}{Ok
}{\void}
402 Returns TRUE if the socket is initialized and ready and FALSE in other
408 \membersection{wxSocketBase::RestoreState
}\label{wxsocketbaserestorestate
}
410 \func{void
}{RestoreState
}{\void}
412 This function restores the previous state of the socket, as saved
413 with
\helpref{SaveState
}{wxsocketbasesavestate
}
415 Calls to SaveState and RestoreState can be nested.
419 \helpref{wxSocketBase::SaveState
}{wxsocketbasesavestate
}
424 \membersection{wxSocketBase::SaveState
}\label{wxsocketbasesavestate
}
426 \func{void
}{SaveState
}{\void}
428 This function saves the current state of the socket in a stack. Socket
429 state includes flags, as set with
\helpref{SetFlags
}{wxsocketbasesetflags
},
430 event mask, as set with
\helpref{SetNotify
}{wxsocketbasesetnotify
} and
431 \helpref{Notify
}{wxsocketbasenotify
}, and current settings for the
432 asynchronous callbacks, as set with
\helpref{Callback
}{wxsocketbasecallback
}
433 and
\helpref{CallbackData
}{wxsocketbasecallbackdata
}.
435 Calls to SaveState and RestoreState can be nested.
439 \helpref{wxSocketBase::RestoreState
}{wxsocketbaserestorestate
}
444 \membersection{wxSocketBase::SetEventHandler
}\label{wxsocketbaseseteventhandler
}
446 \func{void
}{SetEventHandler
}{\param{wxEvtHandler\&
}{ evt
\_hdlr},
\param{int
}{ id = -
1}}
448 Sets an event handler to be called when a socket event occurs. The
449 handler will be called for those events for which notification is
450 enabled with
\helpref{SetNotify
}{wxsocketbasesetnotify
} and
451 \helpref{Notify
}{wxsocketbasenotify
}.
453 You can also specify a callback function to be called when an event
454 occurs, although if possible, events should be used instead of callbacks.
455 See
\helpref{Callback
}{wxsocketbasecallback
} and
456 \helpref{CallbackData
}{wxsocketbasecallbackdata
}.
458 \wxheading{Parameters
}
460 \docparam{evt
\_hdlr}{Specifies the event handler you want to use.
}
462 \docparam{id
}{The id of socket event.
}
466 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
467 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
468 \helpref{wxSocketEvent
}{wxsocketevent
},
469 \helpref{wxEvtHandler
}{wxevthandler
},
470 \helpref{wxSocketBase::Callback
}{wxsocketbasecallback
},
471 \helpref{wxSocketBase::CallbackData
}{wxsocketbasecallbackdata
}
476 \membersection{wxSocketBase::SetFlags
}\label{wxsocketbasesetflags
}
478 \func{void
}{SetFlags
}{\param{wxSocketBase::wxSockFlags
}{ flags
}}
481 \begin{twocollist
}\itemsep=
0pt
482 \twocolitem{{\bf wxSOCKET
\_NONE}}{Normal functionality.
}
483 \twocolitem{{\bf wxSOCKET
\_NOWAIT}}{Read/write as much data as possible and return immediately.
}
484 \twocolitem{{\bf wxSOCKET
\_WAITALL}}{Wait for all required data to be read/written unless an error occurs.
}
485 \twocolitem{{\bf wxSOCKET
\_BLOCK}}{Block the GUI (do not yield) while reading/writing data.
}
488 A brief overview on how to use these flags follows.
490 If no flag is specified (this is the same as
{\bf wxSOCKET
\_NONE}),
491 IO calls will return after some data has been read or written, even
492 when the transfer might not be complete. This is the same as issuing
493 exactly one blocking low-level call to recv() or send(). Note that
494 {\it blocking
} here refers to when the function returns, not to whether
495 the GUI blocks during this time.
497 If
{\bf wxSOCKET
\_NOWAIT} is specified, IO calls will return immediately.
498 Read operations will retrieve only available data. Write operations will
499 write as much data as possible, depending on how much space is available
500 in the output buffer. This is the same as issuing exactly one nonblocking
501 low-level call to recv() or send(). Note that
{\it nonblocking
} here
502 refers to when the function returns, not to whether the GUI blocks during
505 If
{\bf wxSOCKET
\_WAITALL} is specified, IO calls won't return until ALL
506 the data has been read or written (or until an error occurs), blocking if
507 necessary, and issuing several low level calls if necessary. This is the
508 same as having a loop which makes as many blocking low-level calls to
509 recv() or send() as needed so as to transfer all the data. Note that
510 {\it blocking
} here refers to when the function returns, not to whether
511 the GUI blocks during this time.
513 The
{\bf wxSOCKET
\_BLOCK} flag controls whether the GUI blocks during
514 IO operations. If this flag is specified, the socket will not yield
515 during IO calls, so the GUI will remain blocked until the operation
516 completes. If it is not used, then the application must take extra
517 care to avoid unwanted reentrance.
521 {\bf wxSOCKET
\_NONE} will try to read at least SOME data, no matter how much.
523 {\bf wxSOCKET
\_NOWAIT} will always return immediately, even if it cannot
524 read or write ANY data.
526 {\bf wxSOCKET
\_WAITALL} will only return when it has read or written ALL
529 {\bf wxSOCKET
\_BLOCK} has nothing to do with the previous flags and
530 it controls whether the GUI blocks.
535 \membersection{wxSocketBase::SetNotify
}\label{wxsocketbasesetnotify
}
537 \func{void
}{SetNotify
}{\param{wxSocketEventFlags
}{ flags
}}
539 SetNotify specifies which socket events are to be sent to the event handler.
540 The
{\it flags
} parameter is a combination of flags ORed toghether. The
541 following flags can be used:
544 \begin{twocollist
}\itemsep=
0pt
545 \twocolitem{{\bf wxSOCKET
\_INPUT\_FLAG}}{to receive wxSOCKET
\_INPUT}
546 \twocolitem{{\bf wxSOCKET
\_OUTPUT\_FLAG}}{to receive wxSOCKET
\_OUTPUT}
547 \twocolitem{{\bf wxSOCKET
\_CONNECTION\_FLAG}}{to receive wxSOCKET
\_CONNECTION}
548 \twocolitem{{\bf wxSOCKET
\_LOST\_FLAG}}{to receive wxSOCKET
\_LOST}
554 sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
558 In this example, the user will be notified about incoming socket data and
559 whenever the connection is closed.
561 For more information on socket events see
\helpref{wxSocket events
}{wxsocketbase
}.
566 \membersection{wxSocketBase::SetTimeout
}\label{wxsocketbasesettimeout
}
568 \func{void
}{SetTimeout
}{\param{int
}{seconds
}}
570 This function sets the default socket timeout in seconds. This timeout
571 applies to all IO calls, and also to the
\helpref{Wait
}{wxsocketbasewait
}
572 family of functions if you don't specify a wait interval. Initially, the
573 default is set to
10 minutes.
578 \membersection{wxSocketBase::Peek
}\label{wxsocketbasepeek
}
580 \func{wxSocketBase\&
}{Peek
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
582 This function peeks a buffer of
{\it nbytes
} bytes from the socket.
583 Peeking a buffer doesn't delete it from the socket input queue.
585 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually peeked.
587 Use
\helpref{Error
}{wxsocketbaseerror
} to determine if the operation succeeded.
589 \wxheading{Parameters
}
591 \docparam{buffer
}{Buffer where to put peeked data.
}
593 \docparam{nbytes
}{Number of bytes.
}
595 \wxheading{Return value
}
597 Returns a reference to the current object.
599 \wxheading{Remark/Warning
}
601 The exact behaviour of wxSocketBase::Peek depends on the combination
602 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
606 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
607 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
608 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
609 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
614 \membersection{wxSocketBase::Read
}\label{wxsocketbaseread
}
616 \func{wxSocketBase\&
}{Read
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
618 This function reads a buffer of
{\it nbytes
} bytes from the socket.
620 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually read.
622 Use
\helpref{Error
}{wxsocketbaseerror
} to determine if the operation succeeded.
624 \wxheading{Parameters
}
626 \docparam{buffer
}{Buffer where to put read data.
}
628 \docparam{nbytes
}{Number of bytes.
}
630 \wxheading{Return value
}
632 Returns a reference to the current object.
634 \wxheading{Remark/Warning
}
636 The exact behaviour of wxSocketBase::Read depends on the combination
637 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
641 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
642 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
643 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
644 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
649 \membersection{wxSocketBase::ReadMsg
}\label{wxsocketbasereadmsg
}
651 \func{wxSocketBase\&
}{ReadMsg
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
653 This function reads a buffer sent by
\helpref{WriteMsg
}{wxsocketbasewritemsg
}
654 on a socket. If the buffer passed to the function isn't big enough, the
655 remaining bytes will be discarded. This function always waits for the
656 buffer to be entirely filled, unless an error occurs.
658 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually read.
660 Use
\helpref{Error
}{wxsocketbaseerror
} to determine if the operation succeeded.
662 \wxheading{Parameters
}
664 \docparam{buffer
}{Buffer where to put read data.
}
666 \docparam{nbytes
}{Size of the buffer.
}
668 \wxheading{Return value
}
670 Returns a reference to the current object.
672 \wxheading{Remark/Warning
}
674 wxSocketBase::ReadMsg will behave as if the
{\bf wxSOCKET
\_WAITALL} flag
675 was always set and it will always ignore the
{\bf wxSOCKET
\_NOWAIT} flag.
676 The exact behaviour of ReadMsg depends on the
{\bf wxSOCKET
\_BLOCK} flag.
677 For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
681 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
682 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
683 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
684 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
},
685 \helpref{wxSocketBase::WriteMsg
}{wxsocketbasewritemsg
}
690 \membersection{wxSocketBase::Unread
}\label{wxsocketbaseunread
}
692 \func{wxSocketBase\&
}{Unread
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
694 This function unreads a buffer. That is, the data in the buffer is put back
695 in the incoming queue. This function is not affected by wxSocket flags.
697 If you use
\helpref{LastCount
}{wxsocketbaselastcount
}, it will always return
{\it nbytes
}.
699 If you use
\helpref{Error
}{wxsocketbaseerror
}, it will always return FALSE.
701 \wxheading{Parameters
}
703 \docparam{buffer
}{Buffer to be unread.
}
705 \docparam{nbytes
}{Number of bytes.
}
707 \wxheading{Return value
}
709 Returns a reference to the current object.
713 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
714 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
715 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
720 \membersection{wxSocketBase::Wait
}\label{wxsocketbasewait
}
722 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
724 This function waits until one of the following conditions is TRUE. Note
725 that it is recommended to use the individual Wait functions to wait for
726 the required condition, instead of this one.
729 \item The socket becomes readable.
730 \item The socket becomes writable.
731 \item An ongoing connection request has completed (only for clients)
732 \item An incoming connection request has arrived (only for servers)
733 \item The connection has been closed.
736 \wxheading{Parameters
}
738 \docparam{seconds
}{Number of seconds to wait.
739 If -
1, it will wait for the default timeout,
740 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
742 \docparam{millisecond
}{Number of milliseconds to wait.
}
744 \wxheading{Return value
}
746 Returns TRUE when any of the above conditions is satisfied,
747 FALSE if the timeout was reached.
751 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
752 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
753 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
758 \membersection{wxSocketBase::WaitForRead
}\label{wxsocketbasewaitforread
}
760 \func{bool
}{WaitForRead
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
762 This function waits until the socket is readable. This might mean that
763 queued data is available for reading or, for streamed sockets, that
764 the connection has been closed, so that a
\helpref{Read
}{wxsocketbaseread
},
765 \helpref{ReadMsg
}{wxsocketbasereadmsg
} or
\helpref{Peek
}{wxsocketbasepeek
}
766 operation is guaranteed to complete immediately (unless the
767 {\bf wxSOCKET
\_WAITALL} flag is set).
769 \wxheading{Parameters
}
771 \docparam{seconds
}{Number of seconds to wait.
772 If -
1, it will wait for the default timeout,
773 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
775 \docparam{millisecond
}{Number of milliseconds to wait.
}
777 \wxheading{Return value
}
779 Returns TRUE if there is data to be read, FALSE if the timeout was reached
784 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
},
785 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
786 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
791 \membersection{wxSocketBase::WaitForWrite
}\label{wxsocketbasewaitforwrite
}
793 \func{bool
}{WaitForWrite
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
795 This function waits until the socket becomes writable. This might mean that
796 the socket is ready to send new data, or for streamed sockets, that the
797 connection has been closed, so that a
\helpref{Write
}{wxsocketbasewrite
}
798 or
\helpref{ReadMsg
}{wxsocketbasewritemsg
} operation is guaranteed to
799 complete immediately (unless the
{\bf wxSOCKET
\_WAITALL} flag is set).
801 \wxheading{Parameters
}
803 \docparam{seconds
}{Number of seconds to wait.
804 If -
1, it will wait for the default timeout,
805 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
807 \docparam{millisecond
}{Number of milliseconds to wait.
}
809 \wxheading{Return value
}
811 Returns TRUE if the socket becomes writable, FALSE if the timeout was reached.
815 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
},
816 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
817 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
822 \membersection{wxSocketBase::WaitForLost
}\label{wxsocketbasewaitforlost
}
824 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
826 This function waits until the connection is lost. This may happen if
827 the peer gracefully closes the connection or if the connection breaks.
829 \wxheading{Parameters
}
831 \docparam{seconds
}{Number of seconds to wait.
832 If -
1, it will wait for the default timeout,
833 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
835 \docparam{millisecond
}{Number of milliseconds to wait.
}
837 \wxheading{Return value
}
839 Returns TRUE if the connection was lost, FALSE if the timeout was reached.
843 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
844 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
845 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
850 \membersection{wxSocketBase::Write
}\label{wxsocketbasewrite
}
852 \func{wxSocketBase\&
}{Write
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
854 This function writes a buffer of
{\it nbytes
} bytes to the socket.
856 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually written.
858 Use
\helpref{Error
}{wxsocketbaseerror
} to determine if the operation succeeded.
860 \wxheading{Parameters
}
862 \docparam{buffer
}{Buffer with the data to be sent.
}
864 \docparam{nbytes
}{Number of bytes.
}
866 \wxheading{Return value
}
868 Returns a reference to the current object.
870 \wxheading{Remark/Warning
}
872 The exact behaviour of wxSocketBase::Write depends on the combination
873 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
877 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
878 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
879 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
880 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
885 \membersection{wxSocketBase::WriteMsg
}\label{wxsocketbasewritemsg
}
887 \func{wxSocketBase\&
}{WriteMsg
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
889 This function writes a buffer of
{\it nbytes
} bytes from the socket, but it
890 writes a short header before so that
\helpref{ReadMsg
}{wxsocketbasereadmsg
}
891 knows how much data should it actually read. So, a buffer sent with WriteMsg
892 {\bf must
} be read with ReadMsg. This function always waits for the entire
893 buffer to be sent, unless an error occurs.
895 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually written.
897 Use
\helpref{Error
}{wxsocketbaseerror
} to determine if the operation succeeded.
899 \wxheading{Parameters
}
901 \docparam{buffer
}{Buffer with the data to be sent.
}
903 \docparam{nbytes
}{Number of bytes to send.
}
905 \wxheading{Return value
}
907 Returns a reference to the current object.
909 \wxheading{Remark/Warning
}
911 wxSocketBase::WriteMsg will behave as if the
{\bf wxSOCKET
\_WAITALL} flag
912 was always set and it will always ignore the
{\bf wxSOCKET
\_NOWAIT} flag.
913 The exact behaviour of WriteMsg depends on the
{\bf wxSOCKET
\_BLOCK} flag.
914 For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
918 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
919 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
920 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
921 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
},
922 \helpref{wxSocketBase::ReadMsg
}{wxsocketbasereadmsg
}
925 % ---------------------------------------------------------------------------
926 % CLASS wxSocketClient
927 % ---------------------------------------------------------------------------
929 \section{\class{wxSocketClient
}}\label{wxsocketclient
}
931 \wxheading{Derived from
}
933 \helpref{wxSocketBase
}{wxsocketbase
}
935 \wxheading{Include files
}
939 % ---------------------------------------------------------------------------
941 % ---------------------------------------------------------------------------
945 \membersection{wxSocketClient::wxSocketClient
}
947 \func{}{wxSocketClient
}{\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
951 \wxheading{Parameters
}
953 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
958 \membersection{wxSocketClient::
\destruct{wxSocketClient
}}
960 \func{}{\destruct{wxSocketClient
}}{\void}
967 \membersection{wxSocketClient::Connect
}\label{wxsocketclientconnect
}
969 \func{bool
}{Connect
}{\param{wxSockAddress\&
}{ address
},
\param{bool
}{ wait = TRUE
}}
971 Connects to a server using the specified address.
973 If
{\it wait
} is TRUE, Connect will wait until the connection completes.
974 {\bf Warning:
} This will block the GUI.
976 If
{\it wait
} is FALSE, Connect will try to establish the connection and
977 return immediately, without blocking the GUI. When used this way, even if
978 Connect returns FALSE, the connection request can be completed later.
979 To detect this, use
\helpref{WaitOnConnect
}{wxsocketclientwaitonconnect
},
980 or catch
{\bf wxSOCKET
\_CONNECTION} events (for successful establishment)
981 and
{\bf wxSOCKET
\_LOST} events (for connection failure).
983 \wxheading{Parameters
}
985 \docparam{address
}{Address of the server.
}
987 \docparam{wait
}{If TRUE, waits for the connection to complete.
}
989 \wxheading{Return value
}
991 Returns TRUE if the connection is established and no error occurs.
993 If
{\it wait
} was TRUE, and Connect returns FALSE, an error occured
994 and the connection failed.
996 If
{\it wait
} was FALSE, and Connect returns FALSE, you should still
997 be prepared to handle the completion of this connection request, either
998 with
\helpref{WaitOnConnect
}{wxsocketclientwaitonconnect
} or by watching
999 {\bf wxSOCKET
\_CONNECTION} and
{\bf wxSOCKET
\_LOST} events.
1001 \wxheading{See also
}
1003 \helpref{wxSocketClient::WaitOnConnect
}{wxsocketclientwaitonconnect
},
1004 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
1005 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
1010 \membersection{wxSocketClient::WaitOnConnect
}\label{wxsocketclientwaitonconnect
}
1012 \func{bool
}{WaitOnConnect
}{\param{long
}{ seconds = -
1},
\param{long
}{ milliseconds =
0}}
1014 Wait until a connection request completes, or until the specified timeout
1015 elapses. Use this function after issuing a call to
\helpref{Connect
}{wxsocketclientconnect
}
1016 with
{\it wait
} set to FALSE.
1018 \wxheading{Parameters
}
1020 \docparam{seconds
}{Number of seconds to wait.
1021 If -
1, it will wait for the default timeout,
1022 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
1024 \docparam{millisecond
}{Number of milliseconds to wait.
}
1026 \wxheading{Return value
}
1028 If the connection is succesfully established, returns TRUE.
1030 If the timeout expires, or if the connection fails, returns FALSE.
1031 To distinguish between these two conditions, use
\helpref{IsConnected
}{wxsocketbaseisconnected
}
1033 \wxheading{See also
}
1035 \helpref{wxSocketClient::Connect
}{wxsocketclientconnect
},
1036 \helpref{wxSocketBase::IsConnected
}{wxsocketbaseisconnected
}
1038 % ---------------------------------------------------------------------------
1039 % CLASS: wxSocketEvent
1040 % ---------------------------------------------------------------------------
1041 \section{\class{wxSocketEvent
}}\label{wxsocketevent
}
1043 This event class contains information about socket events.
1045 \wxheading{Derived from
}
1047 \helpref{wxEvent
}{wxevent
}
1049 \wxheading{Include files
}
1053 \wxheading{Event table macros
}
1055 To process a socket event, use these event handler macros to direct input to member
1056 functions that take a wxSocketEvent argument.
1059 \begin{twocollist
}\itemsep=
0pt
1060 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{Process a socket event, supplying the member function.
}
1063 \wxheading{See also
}
1065 \helpref{wxSocketBase
}{wxsocketbase
},
1066 \helpref{wxSocketClient
}{wxsocketclient
},
1067 \helpref{wxSocketServer
}{wxsocketserver
}
1069 \latexignore{\rtfignore{\wxheading{Members
}}}
1071 \membersection{wxSocketEvent::wxSocketEvent
}
1073 \func{}{wxSocketEvent
}{\param{int
}{ id =
0}}
1077 \membersection{wxSocketEvent::Socket
}\label{wxsocketeventsocket
}
1079 \constfunc{wxSocketBase *
}{Socket
}{\void}
1081 Returns the socket object to which this event refers to. This makes
1082 it possible to use the same event handler for different sockets.
1084 \membersection{wxSocketEvent::SocketEvent
}\label{wxsocketeventsocketevent
}
1086 \constfunc{wxSocketNotify
}{SocketEvent
}{\void}
1088 Returns the socket event type.
1090 % ---------------------------------------------------------------------------
1091 % CLASS: wxSocketServer
1092 % ---------------------------------------------------------------------------
1093 \section{\class{wxSocketServer
}}\label{wxsocketserver
}
1095 \wxheading{Derived from
}
1097 \helpref{wxSocketBase
}{wxsocketbase
}
1099 \wxheading{Include files
}
1103 % ---------------------------------------------------------------------------
1105 % ---------------------------------------------------------------------------
1106 \latexignore{\rtfignore{\wxheading{Members
}}}
1111 \membersection{wxSocketServer::wxSocketServer
}\label{wxsocketserverconstr
}
1113 \func{}{wxSocketServer
}{\param{wxSockAddress\&
}{ address
},
\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
1115 Constructs a new server and tries to bind to the specified
{\it address
}.
1116 Before trying to accept new connections, test whether it succeeded with
1117 \helpref{wxSocketBase::Ok
}{wxsocketbaseok
}.
1119 \wxheading{Parameters
}
1121 \docparam{address
}{Specifies the local address for the server (e.g. port number).
}
1123 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
1128 \membersection{wxSocketServer::
\destruct{wxSocketServer
}}
1130 \func{}{\destruct{wxSocketServer
}}{\void}
1132 Destructor (it doesn't close the accepted connections).
1137 \membersection{wxSocketServer::Accept
}\label{wxsocketserveraccept
}
1139 \func{wxSocketBase *
}{Accept
}{\param{bool
}{ wait = TRUE
}}
1141 Accepts an incoming connection request, and creates a new
1142 \helpref{wxSocketBase
}{wxsocketbase
} object which represents
1143 the server-side of the connection.
1145 If
{\it wait
} is TRUE and there are no pending connections to be
1146 accepted, it will wait for the next incoming connection to arrive.
1147 {\bf Warning:
} This will block the GUI.
1149 If
{\it wait
} is FALSE, it will try to accept a pending connection
1150 if there is one, but it will always return immediately without blocking
1151 the GUI. If you want to use Accept in this way, you can either check for
1152 incoming connections with
\helpref{WaitForAccept
}{wxsocketserverwaitforaccept
}
1153 or catch
{\bf wxSOCKET
\_CONNECTION} events, then call Accept once you know
1154 that there is an incoming connection waiting to be accepted.
1156 \wxheading{Return value
}
1158 Returns an opened socket connection, or NULL if an error occured or
1159 if the
{\it wait
} parameter was FALSE and there were no pending
1162 \wxheading{See also
}
1164 \helpref{wxSocketServer::WaitForAccept
}{wxsocketserverwaitforaccept
},
1165 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
1166 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
1167 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}
1172 \membersection{wxSocketServer::AcceptWith
}\label{wxsocketserveracceptwith
}
1174 \func{bool
}{AcceptWith
}{\param{wxSocketBase\&
}{ socket
},
\param{bool
}{ wait = TRUE
}}
1176 Accept an incoming connection using the specified socket object.
1178 \wxheading{Parameters
}
1180 \docparam{socket
}{Socket to be initialized
}
1182 \wxheading{Return value
}
1184 Returns TRUE on success, or FALSE if an error occured or if the
1185 {\it wait
} parameter was FALSE and there were no pending
1188 \helpref{wxSocketServer::WaitForAccept
}{wxsocketserverwaitforaccept
},
1189 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
1190 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
1191 \helpref{wxSocketServer::Accept
}{wxsocketserveraccept
} for a detailed explanation
1196 \membersection{wxSocketServer::WaitForAccept
}\label{wxsocketserverwaitforaccept
}
1198 \func{bool
}{WaitForAccept
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
1200 This function waits for an incoming connection. Use it if you want to call
1201 \helpref{Accept
}{wxsocketserveraccept
} or
\helpref{AcceptWith
}{wxsocketserveracceptwith
}
1202 with
{\it wait
} set to FALSE, to detect when an incoming connection is waiting
1205 \wxheading{Parameters
}
1207 \docparam{seconds
}{Number of seconds to wait.
1208 If -
1, it will wait for the default timeout,
1209 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
1211 \docparam{millisecond
}{Number of milliseconds to wait.
}
1213 \wxheading{Return value
}
1215 Returns TRUE if an incoming connection arrived, FALSE if the timeout elapsed.
1217 \wxheading{See also
}
1219 \helpref{wxSocketServer::Accept
}{wxsocketserveraccept
},
1220 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}