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 \wxheading{Derived from
}
16 \helpref{wxEvtHandler
}{wxevthandler
}
18 \wxheading{Include files
}
22 \wxheading{wxSocket errors
}
25 \begin{twocollist
}\itemsep=
0pt
26 \twocolitem{{\bf wxSOCKET
\_NOERROR}}{No error happened.
}
27 \twocolitem{{\bf wxSOCKET
\_INVOP}}{Invalid operation.
}
28 \twocolitem{{\bf wxSOCKET
\_IOERR}}{Input/Output error.
}
29 \twocolitem{{\bf wxSOCKET
\_INVADDR}}{Invalid address passed to wxSocket.
}
30 \twocolitem{{\bf wxSOCKET
\_INVSOCK}}{Invalid socket (uninitialized).
}
31 \twocolitem{{\bf wxSOCKET
\_NOHOST}}{No corresponding host.
}
32 \twocolitem{{\bf wxSOCKET
\_INVPORT}}{Invalid port.
}
33 \twocolitem{{\bf wxSOCKET
\_WOULDBLOCK}}{The socket is non-blocking and the operation would block.
}
34 \twocolitem{{\bf wxSOCKET
\_TIMEDOUT}}{The timeout for this operation expired.
}
35 \twocolitem{{\bf wxSOCKET
\_MEMERR}}{Memory exhausted.
}
38 \wxheading{wxSocket events
}
41 \begin{twocollist
}\itemsep=
0pt
42 \twocolitem{{\bf wxSOCKET
\_INPUT}}{There is data available for reading.
}
43 \twocolitem{{\bf wxSOCKET
\_OUTPUT}}{The socket is ready to be written to.
}
44 \twocolitem{{\bf wxSOCKET
\_CONNECTION}}{Incoming connection (server), or connection establishment (client).
}
45 \twocolitem{{\bf wxSOCKET
\_LOST}}{The connection has been closed.
}
48 A brief note on how to use these events:
50 The
{\bf wxSOCKET
\_INPUT} event will be issued whenever there is data
51 available for reading. This will be the case if the input queue was
52 empty and new data arrives, or if the application has read some data
53 yet there is still more data available. This means that the application
54 does not need to read all available data in response to a
55 {\bf wxSOCKET
\_INPUT} event, as more events will be produced as
58 The
{\bf wxSOCKET
\_OUTPUT} event is issued when a socket is first
59 connected with
\helpref{Connect
}{wxsocketclientconnect
} or accepted
60 with
\helpref{Accept
}{wxsocketserveraccept
}. After that, new
61 events will be generated only after an output operation fails
62 with
{\bf wxSOCKET
\_WOULDBLOCK} and buffer space becomes available
63 again. This means that the application should assume that it
64 can write data to the socket until an
{\bf wxSOCKET
\_WOULDBLOCK}
65 error occurs; after this, whenever the socket becomes writable
66 again the application will be notified with another
67 {\bf wxSOCKET
\_OUTPUT} event.
69 The
{\bf wxSOCKET
\_CONNECTION} event is issued when a delayed connection
70 request completes succesfully (client) or when a new connection arrives
71 at the incoming queue (server).
73 The
{\bf wxSOCKET
\_LOST} event is issued when a close indication is
74 received for the socket. This means that the connection broke down or
75 that it was closed by the peer. Also, this event will be issued if
76 a delayed connection request fails.
78 \wxheading{Event handling
}
80 To process events from a socket, use the following event handler macro to direct
81 input to member functions that take a
\helpref{wxSocketEvent
}{wxsocketevent
} argument.
84 \begin{twocollist
}\itemsep=
0pt
85 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{A socket event occured.
}
90 \helpref{wxSocketEvent
}{wxsocketevent
},
91 \helpref{wxSocketClient
}{wxsocketclient
},
92 \helpref{wxSocketServer
}{wxsocketserver
},
93 \helpref{Sockets sample
}{samplesockets
}
95 % ---------------------------------------------------------------------------
97 % ---------------------------------------------------------------------------
99 \latexignore{\rtfignore{\wxheading{Members
}}}
101 \membersection{wxSocketBase::wxSocketBase
}
103 \func{}{wxSocketBase
}{\void}
105 Default constructor. Don't use it; use
\helpref{wxSocketClient
}{wxsocketclient
}
106 or
\helpref{wxSocketServer
}{wxsocketserver
}.
108 \membersection{wxSocketBase::
\destruct{wxSocketBase
}}
110 \func{}{\destruct{wxSocketBase
}}{\void}
114 % ---------------------------------------------------------------------------
116 % ---------------------------------------------------------------------------
122 \membersection{wxSocketBase::SetFlags
}\label{wxsocketbasesetflags
}
124 \func{void
}{SetFlags
}{\param{wxSocketBase::wxSockFlags
}{ flags
}}
127 \begin{twocollist
}\itemsep=
0pt
128 \twocolitem{{\bf wxSOCKET
\_NONE}}{Normal functionality.
}
129 \twocolitem{{\bf wxSOCKET
\_NOWAIT}}{Read/write as much data as possible and return immediately.
}
130 \twocolitem{{\bf wxSOCKET
\_WAITALL}}{Wait for all required data to be read/written unless an error occurs.
}
131 \twocolitem{{\bf wxSOCKET
\_BLOCK}}{Block the GUI (do not yield) while reading/writing data.
}
134 A brief overview on how to use these flags follows.
136 If no flag is specified (this is the same as
{\bf wxSOCKET
\_NONE}),
137 IO calls will return after some data has been read or written, even
138 when the transfer might not be complete. This is the same as issuing
139 exactly one blocking low-level call to recv() or send(). Note that
140 {\it blocking
} here refers to when the function returns, not to whether
141 the GUI blocks during this time.
143 If
{\bf wxSOCKET
\_NOWAIT} is specified, IO calls will return immediately.
144 Read operations will retrieve only available data. Write operations will
145 write as much data as possible, depending on how much space is available
146 in the output buffer. This is the same as issuing exactly one nonblocking
147 low-level call to recv() or send(). Note that
{\it nonblocking
} here
148 refers to when the function returns, not to whether the GUI blocks during
151 If
{\bf wxSOCKET
\_WAITALL} is specified, IO calls won't return until ALL
152 the data has been read or written (or until an error occurs), blocking if
153 necessary, and issuing several low level calls if necessary. This is the
154 same as having a loop which makes as many blocking low-level calls to
155 recv() or send() as needed so as to transfer all the data. Note that
156 {\it blocking
} here refers to when the function returns, not to whether
157 the GUI blocks during this time.
159 The
{\bf wxSOCKET
\_BLOCK} flag controls whether the GUI blocks during
160 IO operations. If this flag is specified, the socket will not yield
161 during IO calls, so the GUI will remain blocked until the operation
162 completes. If it is not used, then the application must take extra
163 care to avoid unwanted reentrance.
167 {\bf wxSOCKET
\_NONE} will try to read at least SOME data, no matter how much.
169 {\bf wxSOCKET
\_NOWAIT} will always return immediately, even if it cannot
170 read or write ANY data.
172 {\bf wxSOCKET
\_WAITALL} will only return when it has read or written ALL
175 {\bf wxSOCKET
\_BLOCK} has nothing to do with the previous flags and
176 it controls whether the GUI blocks.
181 \membersection{wxSocketBase::SetNotify
}\label{wxsocketbasesetnotify
}
183 \func{void
}{SetNotify
}{\param{wxSocketEventFlags
}{ flags
}}
185 SetNotify specifies which socket events are to be sent to the event handler.
186 The
{\it flags
} parameter is a combination of flags ORed toghether. The
187 following flags can be used:
190 \begin{twocollist
}\itemsep=
0pt
191 \twocolitem{{\bf wxSOCKET
\_INPUT\_FLAG}}{to receive wxSOCKET
\_INPUT}
192 \twocolitem{{\bf wxSOCKET
\_OUTPUT\_FLAG}}{to receive wxSOCKET
\_OUTPUT}
193 \twocolitem{{\bf wxSOCKET
\_CONNECTION\_FLAG}}{to receive wxSOCKET
\_CONNECTION}
194 \twocolitem{{\bf wxSOCKET
\_LOST\_FLAG}}{to receive wxSOCKET
\_LOST}
200 sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
204 In this example, the user will be notified about incoming socket data and
205 whenever the connection is closed.
207 For more information on socket events see
\helpref{wxSocket events
}{wxsocketbase
}.
212 \membersection{wxSocketBase::SetTimeout
}\label{wxsocketbasesettimeout
}
214 \func{void
}{SetTimeout
}{\param{int
}{seconds
}}
216 This function sets the default socket timeout in seconds. This timeout
217 applies to all IO calls, and also to the
\helpref{Wait
}{wxsocketbasewait
}
218 family of functions if you don't specify a wait interval. Initially, the
219 default is set to
10 minutes.
224 \membersection{wxSocketBase::Notify
}\label{wxsocketbasenotify
}
226 \func{void
}{Notify
}{\param{bool
}{ notify
}}
228 According to the
{\it notify
} value, this function enables
229 or disables socket events. If
{\it notify
} is TRUE, the events
230 configured with
\helpref{SetNotify
}{wxsocketbasesetnotify
} will
231 be sent to the application. If
{\it notify
} is FALSE; no events
238 \membersection{wxSocketBase::Ok
}\label{wxsocketbaseok
}
240 \constfunc{bool
}{Ok
}{\void}
242 Returns TRUE if the socket is initialized and ready and FALSE in other
245 \membersection{wxSocketBase::Error
}\label{wxsocketbaseerror
}
247 \constfunc{bool
}{Error
}{\void}
249 Returns TRUE if an error occured in the last IO operation.
251 Use this function to check for an error condition after one of the
252 following calls: Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
254 \membersection{wxSocketBase::IsConnected
}\label{wxsocketbaseisconnected
}
256 \constfunc{bool
}{IsConnected
}{\void}
258 Returns TRUE if the socket is connected.
260 \membersection{wxSocketBase::IsData
}\label{wxsocketbaseisdata
}
262 \constfunc{bool
}{IsData
}{\void}
264 Returns TRUE if there is data available to be read.
266 \membersection{wxSocketBase::IsDisconnected
}\label{wxsocketbasedisconnected
}
268 \constfunc{bool
}{IsDisconnected
}{\void}
270 Returns TRUE if the socket is not connected.
272 \membersection{wxSocketBase::LastCount
}\label{wxsocketbaselastcount
}
274 \constfunc{wxUint32
}{LastCount
}{\void}
276 Returns the number of bytes read or written by the last IO call.
278 Use this function to get the number of bytes actually transferred
279 after using one of the following IO calls: Read, Write, ReadMsg,
280 WriteMsg, Peek, Unread, Discard.
282 \membersection{wxSocketBase::LastError
}\label{wxsocketbaselasterror
}
284 \constfunc{wxSocketError
}{LastError
}{\void}
286 Returns the last wxSocket error. See
\helpref{wxSocket errors
}{wxsocketbase
}.
288 Please note that this function merely returns the last error code,
289 but it should not be used to determine if an error has occured (this
290 is because successful operations do not change the LastError value).
291 Use
\helpref{Error
}{wxsocketbaseerror
} first, in order to determine
292 if the last IO call failed. If this returns TRUE, use LastError()
293 to discover the cause of the error.
295 % ---------------------------------------------------------------------------
297 % ---------------------------------------------------------------------------
301 \membersection{wxSocketBase::Peek
}\label{wxsocketbasepeek
}
303 \func{wxSocketBase\&
}{Peek
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
305 This function peeks a buffer of
{\it nbytes
} bytes from the socket.
306 Peeking a buffer doesn't delete it from the socket input queue.
308 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually peeked.
310 Use
\helpref{Error
}{wxsocketbaseerror
} to determine if the operation succeeded.
312 \wxheading{Parameters
}
314 \docparam{buffer
}{Buffer where to put peeked data.
}
316 \docparam{nbytes
}{Number of bytes.
}
318 \wxheading{Return value
}
320 Returns a reference to the current object.
322 \wxheading{Remark/Warning
}
324 The exact behaviour of wxSocketBase::Peek() depends on the combination
325 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
329 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
330 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
331 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
332 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
337 \membersection{wxSocketBase::Read
}\label{wxsocketbaseread
}
339 \func{wxSocketBase\&
}{Read
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
341 This function reads a buffer of
{\it nbytes
} bytes from the socket.
343 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually read.
345 Use
\helpref{Error
}{wxsocketbaseerror
} to determine if the operation succeeded.
347 \wxheading{Parameters
}
349 \docparam{buffer
}{Buffer where to put read data.
}
351 \docparam{nbytes
}{Number of bytes.
}
353 \wxheading{Return value
}
355 Returns a reference to the current object.
357 \wxheading{Remark/Warning
}
359 The exact behaviour of wxSocketBase::Read() depends on the combination
360 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
364 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
365 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
366 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
367 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
372 \membersection{wxSocketBase::Write
}\label{wxsocketbasewrite
}
374 \func{wxSocketBase\&
}{Write
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
376 This function writes a buffer of
{\it nbytes
} bytes to the socket.
378 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually written.
380 Use
\helpref{Error
}{wxsocketbaseerror
} to determine if the operation succeeded.
382 \wxheading{Parameters
}
384 \docparam{buffer
}{Buffer with the data to be sent.
}
386 \docparam{nbytes
}{Number of bytes.
}
388 \wxheading{Return value
}
390 Returns a reference to the current object.
392 \wxheading{Remark/Warning
}
394 The exact behaviour of wxSocketBase::Write() depends on the combination
395 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
399 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
400 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
401 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
402 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
407 \membersection{wxSocketBase::WriteMsg
}\label{wxsocketbasewritemsg
}
409 \func{wxSocketBase\&
}{WriteMsg
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
411 This function writes a buffer of
{\it nbytes
} bytes from the socket, but it
412 writes a short header before so that
\helpref{ReadMsg
}{wxsocketbasereadmsg
}
413 knows how much data should it actually read. So, a buffer sent with WriteMsg
414 {\bf must
} be read with ReadMsg. This function always waits for the entire
415 buffer to be sent, unless an error occurs.
417 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually written.
419 Use
\helpref{Error
}{wxsocketbaseerror
} to determine if the operation succeeded.
421 \wxheading{Parameters
}
423 \docparam{buffer
}{Buffer with the data to be sent.
}
425 \docparam{nbytes
}{Number of bytes to send.
}
427 \wxheading{Return value
}
429 Returns a reference to the current object.
431 \wxheading{Remark/Warning
}
433 wxSocketBase::WriteMsg() will behave as if the
{\bf wxSOCKET
\_WAITALL} flag
434 was always set and it will always ignore the
{\bf wxSOCKET
\_NOWAIT} flag.
435 The exact behaviour of WriteMsg depends on the
{\bf wxSOCKET
\_BLOCK} flag.
436 For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
440 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
441 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
442 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
443 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
},
444 \helpref{wxSocketBase::ReadMsg
}{wxsocketbasereadmsg
}
449 \membersection{wxSocketBase::ReadMsg
}\label{wxsocketbasereadmsg
}
451 \func{wxSocketBase\&
}{ReadMsg
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
453 This function reads a buffer sent by
\helpref{WriteMsg
}{wxsocketbasewritemsg
}
454 on a socket. If the buffer passed to the function isn't big enough, the
455 remaining bytes will be discarded. This function always waits for the
456 buffer to be entirely filled, unless an error occurs.
458 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually read.
460 Use
\helpref{Error
}{wxsocketbaseerror
} to determine if the operation succeeded.
462 \wxheading{Parameters
}
464 \docparam{buffer
}{Buffer where to put read data.
}
466 \docparam{nbytes
}{Size of the buffer.
}
468 \wxheading{Return value
}
470 Returns a reference to the current object.
472 \wxheading{Remark/Warning
}
474 wxSocketBase::ReadMsg() will behave as if the
{\bf wxSOCKET
\_WAITALL} flag
475 was always set and it will always ignore the
{\bf wxSOCKET
\_NOWAIT} flag.
476 The exact behaviour of ReadMsg depends on the
{\bf wxSOCKET
\_BLOCK} flag.
477 For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
481 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
482 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
483 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
484 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
},
485 \helpref{wxSocketBase::WriteMsg
}{wxsocketbasewritemsg
}
490 \membersection{wxSocketBase::Unread
}\label{wxsocketbaseunread
}
492 \func{wxSocketBase\&
}{Unread
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
494 This function unreads a buffer. That is, the data in the buffer is put back
495 in the incoming queue. This function is not affected by wxSocket flags.
497 If you use
\helpref{LastCount
}{wxsocketbaselastcount
}, it will always return
{\it nbytes
}.
499 If you use
\helpref{Error
}{wxsocketbaseerror
}, it will always return FALSE.
501 \wxheading{Parameters
}
503 \docparam{buffer
}{Buffer to be unread.
}
505 \docparam{nbytes
}{Number of bytes.
}
507 \wxheading{Return value
}
509 Returns a reference to the current object.
513 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
514 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
515 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
520 \membersection{wxSocketBase::Discard
}\label{wxsocketbasediscard
}
522 \func{wxSocketBase\&
}{Discard
}{\void}
524 This function simply deletes all bytes in the incoming queue. This function
525 always returns immediately and its operation is not affected by IO flags.
527 Use
\helpref{LastCount
}{wxsocketbaselastcount
} to verify the number of bytes actually discarded.
529 If you use
\helpref{Error
}{wxsocketbaseerror
}, it will always return FALSE.
531 % ---------------------------------------------------------------------------
533 % ---------------------------------------------------------------------------
534 \membersection{wxSocketBase::Wait
}\label{wxsocketbasewait
}
536 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
538 This function waits until one of the following conditions is TRUE. Note
539 that it is recommended to use the individual Wait functions to wait for
540 the required condition, instead of this one.
543 \item There is data available for reading.
544 \item The socket becomes writable.
545 \item An ongoing connection request has completed (only for clients)
546 \item An incoming connection request has arrived (only for servers)
547 \item The connection has been closed.
550 \wxheading{Parameters
}
552 \docparam{seconds
}{Number of seconds to wait.
553 If -
1, it will wait for the default timeout,
554 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
556 \docparam{millisecond
}{Number of milliseconds to wait.
}
558 \wxheading{Return value
}
560 Returns TRUE when any of the above conditions is satisfied,
561 FALSE if the timeout was reached.
565 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
566 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
567 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
572 \membersection{wxSocketBase::WaitForRead
}\label{wxsocketbasewaitforread
}
574 \func{bool
}{WaitForRead
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
576 This function waits until there is data available to be read, or until
579 \wxheading{Parameters
}
581 \docparam{seconds
}{Number of seconds to wait.
582 If -
1, it will wait for the default timeout,
583 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
585 \docparam{millisecond
}{Number of milliseconds to wait.
}
587 \wxheading{Return value
}
589 Returns TRUE if there is data to be read, FALSE if the timeout was reached
594 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
},
595 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
596 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
601 \membersection{wxSocketBase::WaitForWrite
}\label{wxsocketbasewaitforwrite
}
603 \func{bool
}{WaitForWrite
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
605 This function waits until the socket is ready to send data,
606 or until an error occurs.
608 \wxheading{Parameters
}
610 \docparam{seconds
}{Number of seconds to wait.
611 If -
1, it will wait for the default timeout,
612 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
614 \docparam{millisecond
}{Number of milliseconds to wait.
}
616 \wxheading{Return value
}
618 Returns TRUE if you can write to the socket, FALSE if the timeout was
619 reached or an error occured.
623 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
},
624 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
625 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
630 \membersection{wxSocketBase::WaitForLost
}\label{wxsocketbasewaitforlost
}
632 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
634 This function waits until the connection is lost. This may happen if
635 the peer gracefully closes the connection or if the connection breaks.
637 \wxheading{Parameters
}
639 \docparam{seconds
}{Number of seconds to wait.
640 If -
1, it will wait for the default timeout,
641 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
643 \docparam{millisecond
}{Number of milliseconds to wait.
}
645 \wxheading{Return value
}
647 Returns TRUE if the connection was lost, FALSE if the timeout was reached.
651 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
652 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
653 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
655 % ---------------------------------------------------------------------------
657 % ---------------------------------------------------------------------------
662 \membersection{wxSocketBase::RestoreState
}\label{wxsocketbaserestorestate
}
664 \func{void
}{RestoreState
}{\void}
666 This function restores the previous state of the socket, as saved
667 with
\helpref{SaveState
}{wxsocketbasesavestate
}
669 Calls to SaveState and RestoreState can be nested.
673 \helpref{wxSocketBase::SaveState
}{wxsocketbasesavestate
}
678 \membersection{wxSocketBase::SaveState
}\label{wxsocketbasesavestate
}
680 \func{void
}{SaveState
}{\void}
682 This function saves the current state of the socket in a stack. Socket
683 state includes flags, as set with
\helpref{SetFlags
}{wxsocketbasesetflags
},
684 event mask, as set with
\helpref{SetNotify
}{wxsocketbasesetnotify
} and
685 \helpref{Notify
}{wxsocketbasenotify
}, and current settings for the
686 asynchronous callbacks, as set with
\helpref{Callback
}{wxsocketbasecallback
}
687 and
\helpref{CallbackData
}{wxsocketbasecallbackdata
}.
689 Calls to SaveState and RestoreState can be nested.
693 \helpref{wxSocketBase::RestoreState
}{wxsocketbaserestorestate
}
698 \membersection{wxSocketBase::GetLocal
}\label{wxsocketbasegetlocal
}
700 \constfunc{bool
}{GetLocal
}{\param{wxSockAddress\&
}{addr
\_man}}
702 This function returns the local address field of the socket. The local
703 address field contains the complete local address of the socket (local
704 address, local port, ...).
706 \wxheading{Return value
}
708 It returns TRUE if no errors happened, FALSE otherwise.
713 \membersection{wxSocketBase::GetPeer
}\label{wxsocketbasegetpeer
}
715 \constfunc{bool
}{GetPeer
}{\param{wxSockAddress\&
}{addr
\_man}}
717 This function returns the peer address field of the socket. The peer
718 address field contains the complete peer host address of the socket
719 (address, port, ...).
721 \wxheading{Return value
}
723 It returns TRUE if no errors happened, FALSE otherwise.
725 % ---------------------------------------------------------------------------
727 % ---------------------------------------------------------------------------
728 \membersection{wxSocketBase::SetEventHandler
}\label{wxsocketbaseseteventhandler
}
730 \func{void
}{SetEventHandler
}{\param{wxEvtHandler\&
}{ evt
\_hdlr},
\param{int
}{ id = -
1}}
732 Sets an event handler to be called when a socket event occurs. The
733 handler will be called for those events for which notification is
734 enabled with
\helpref{SetNotify
}{wxsocketbasesetnotify
} and
735 \helpref{Notify
}{wxsocketbasenotify
}.
737 You can also specify a callback function to be called when an event
738 occurs, although if possible, events should be used instead of callbacks.
739 See
\helpref{Callback
}{wxsocketbasecallback
} and
740 \helpref{CallbackData
}{wxsocketbasecallbackdata
}.
742 \wxheading{Parameters
}
744 \docparam{evt
\_hdlr}{Specifies the event handler you want to use.
}
746 \docparam{id
}{The id of socket event.
}
750 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
751 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
752 \helpref{wxSocketEvent
}{wxsocketevent
},
753 \helpref{wxEvtHandler
}{wxevthandler
},
754 \helpref{wxSocketBase::Callback
}{wxsocketbasecallback
},
755 \helpref{wxSocketBase::CallbackData
}{wxsocketbasecallbackdata
}
757 \membersection{wxSocketBase::Callback
}\label{wxsocketbasecallback
}
759 \func{wxSocketBase::wxSockCbk
}{Callback
}{\param{wxSocketBase::wxSockCbk
}{ callback
}}
761 You can setup a callback function to be called when an event occurs.
762 The function will be called only for those events for which notification
763 has been enabled with
\helpref{Notify
}{wxsocketbasenotify
} and
764 \helpref{SetNotify
}{wxsocketbasesetnotify
}. The prototype of the
765 callback must be as follows:
768 void SocketCallback(wxSocketBase& sock, wxSocketNotify evt, char *cdata);
771 The first parameter is a reference to the socket object in which the
772 event occured. The second parameter tells you which event occured.
773 (See
\helpref{wxSocket events
}{wxsocketbase
}). The third parameter
774 is the user data you specified using
775 \helpref{CallbackData
}{wxsocketbasecallbackdata
}.
777 Note that events are preferred over callbacks where possible.
779 \wxheading{Return value
}
781 A pointer to the previous callback.
785 \helpref{wxSocketBase::CallbackData
}{wxsocketbasecallbackdata
},
786 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
787 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
789 \membersection{wxSocketBase::CallbackData
}\label{wxsocketbasecallbackdata
}
791 \func{char *
}{CallbackData
}{\param{char *
}{cdata
}}
793 This function sets the the user data which will be passed to a
794 callback function set via
\helpref{Callback
}{wxsocketbasecallback
}.
796 Note that events are preferred over callbacks where possible.
798 \wxheading{Return value
}
800 A pointer to the previous user data.
802 \helpref{wxSocketBase::Callback
}{wxsocketbasecallback
},
803 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
804 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
806 % ---------------------------------------------------------------------------
807 % CLASS wxSocketClient
808 % ---------------------------------------------------------------------------
809 \section{\class{wxSocketClient
}}\label{wxsocketclient
}
811 \wxheading{Derived from
}
813 \helpref{wxSocketBase
}{wxsocketbase
}
815 \wxheading{Include files
}
819 % ---------------------------------------------------------------------------
821 % ---------------------------------------------------------------------------
825 \membersection{wxSocketClient::wxSocketClient
}
827 \func{}{wxSocketClient
}{\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
831 \wxheading{Parameters
}
833 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
838 \membersection{wxSocketClient::
\destruct{wxSocketClient
}}
840 \func{}{\destruct{wxSocketClient
}}{\void}
847 \membersection{wxSocketClient::Connect
}\label{wxsocketclientconnect
}
849 \func{bool
}{Connect
}{\param{wxSockAddress\&
}{ address
},
\param{bool
}{ wait = TRUE
}}
851 Connects to a server using the specified address.
853 If
{\it wait
} is TRUE, Connect will wait until the connection completes.
854 {\bf Warning:
} This will block the GUI.
856 If
{\it wait
} is FALSE, Connect will try to establish the connection and
857 return immediately, without blocking the GUI. When used this way, even if
858 Connect returns FALSE, the connection request can be completed later.
859 To detect this, use
\helpref{WaitOnConnect
}{wxsocketclientwaitonconnect
},
860 or catch
{\bf wxSOCKET
\_CONNECTION} events (for successful establishment)
861 and
{\bf wxSOCKET
\_LOST} events (for connection failure).
863 \wxheading{Parameters
}
865 \docparam{address
}{Address of the server.
}
867 \docparam{wait
}{If TRUE, waits for the connection to complete.
}
869 \wxheading{Return value
}
871 Returns TRUE if the connection is established and no error occurs.
873 If
{\it wait
} was TRUE, and Connect returns FALSE, an error occured
874 and the connection failed.
876 If
{\it wait
} was FALSE, and Connect returns FALSE, you should still
877 be prepared to handle the completion of this connection request, either
878 with
\helpref{WaitOnConnect
}{wxsocketclientwaitonconnect
} or by watching
879 {\bf wxSOCKET
\_CONNECTION} and
{\bf wxSOCKET
\_LOST} events.
883 \helpref{wxSocketClient::WaitOnConnect
}{wxsocketclientwaitonconnect
},
884 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
885 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
890 \membersection{wxSocketClient::WaitOnConnect
}\label{wxsocketclientwaitonconnect
}
892 \func{bool
}{WaitOnConnect
}{\param{long
}{ seconds = -
1},
\param{long
}{ milliseconds =
0}}
894 Wait until a connection request completes, or until the specified timeout
895 elapses. Use this function after issuing a call to
\helpref{Connect
}{wxsocketclientconnect
}
896 with
{\it wait
} set to FALSE.
898 \wxheading{Parameters
}
900 \docparam{seconds
}{Number of seconds to wait.
901 If -
1, it will wait for the default timeout,
902 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
904 \docparam{millisecond
}{Number of milliseconds to wait.
}
906 \wxheading{Return value
}
908 If the connection is succesfully established, returns TRUE.
910 If the timeout expires, or if the connection fails, returns FALSE.
911 To distinguish between these two conditions, use
\helpref{IsConnected
}{wxsocketbaseisconnected
}
915 \helpref{wxSocketClient::Connect
}{wxsocketclientconnect
},
916 \helpref{wxSocketBase::IsConnected
}{wxsocketbaseisconnected
}
918 % ---------------------------------------------------------------------------
919 % CLASS: wxSocketEvent
920 % ---------------------------------------------------------------------------
921 \section{\class{wxSocketEvent
}}\label{wxsocketevent
}
923 This event class contains information about socket events.
925 \wxheading{Derived from
}
927 \helpref{wxEvent
}{wxevent
}
929 \wxheading{Include files
}
933 \wxheading{Event table macros
}
935 To process a socket event, use these event handler macros to direct input to member
936 functions that take a wxSocketEvent argument.
939 \begin{twocollist
}\itemsep=
0pt
940 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{Process a socket event, supplying the member function.
}
945 \helpref{wxSocketBase
}{wxsocketbase
},
946 \helpref{wxSocketClient
}{wxsocketclient
},
947 \helpref{wxSocketServer
}{wxsocketserver
}
949 \latexignore{\rtfignore{\wxheading{Members
}}}
951 \membersection{wxSocketEvent::wxSocketEvent
}
953 \func{}{wxSocketEvent
}{\param{int
}{ id =
0}}
957 \membersection{wxSocketEvent::Socket
}\label{wxsocketeventsocket
}
959 \constfunc{wxSocketBase *
}{Socket
}{\void}
961 Returns the socket object to which this event refers to. This makes
962 it possible to use the same event handler for different sockets.
964 \membersection{wxSocketEvent::SocketEvent
}\label{wxsocketeventsocketevent
}
966 \constfunc{wxSocketNotify
}{SocketEvent
}{\void}
968 Returns the socket event type.
970 % ---------------------------------------------------------------------------
971 % CLASS: wxSocketServer
972 % ---------------------------------------------------------------------------
973 \section{\class{wxSocketServer
}}\label{wxsocketserver
}
975 \wxheading{Derived from
}
977 \helpref{wxSocketBase
}{wxsocketbase
}
979 \wxheading{Include files
}
983 % ---------------------------------------------------------------------------
985 % ---------------------------------------------------------------------------
986 \latexignore{\rtfignore{\wxheading{Members
}}}
991 \membersection{wxSocketServer::wxSocketServer
}\label{wxsocketserverconstr
}
993 \func{}{wxSocketServer
}{\param{wxSockAddress\&
}{ address
},
\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
995 Constructs a new server and tries to bind to the specified
{\it address
}.
996 Before trying to accept new connections, test whether it succeeded with
997 \helpref{wxSocketBase::Ok
}{wxsocketbaseok
}.
999 \wxheading{Parameters
}
1001 \docparam{address
}{Specifies the local address for the server (e.g. port number).
}
1003 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
1008 \membersection{wxSocketServer::
\destruct{wxSocketServer
}}
1010 \func{}{\destruct{wxSocketServer
}}{\void}
1012 Destructor (it doesn't close the accepted connections).
1017 \membersection{wxSocketServer::Accept
}\label{wxsocketserveraccept
}
1019 \func{wxSocketBase *
}{Accept
}{\param{bool
}{ wait = TRUE
}}
1021 Accepts an incoming connection request, and creates a new
1022 \helpref{wxSocketBase
}{wxsocketbase
} object which represents
1023 the server-side of the connection.
1025 If
{\it wait
} is TRUE and there are no pending connections to be
1026 accepted, it will wait for the next incoming connection to arrive.
1027 {\bf Warning:
} This will block the GUI.
1029 If
{\it wait
} is FALSE, it will try to accept a pending connection
1030 if there is one, but it will always return immediately without blocking
1031 the GUI. If you want to use Accept in this way, you can either check for
1032 incoming connections with
\helpref{WaitForAccept
}{wxsocketserverwaitforaccept
}
1033 or catch
{\bf wxSOCKET
\_CONNECTION} events, then call Accept() once you know
1034 that there is an incoming connection waiting to be accepted.
1036 \wxheading{Return value
}
1038 Returns an opened socket connection, or NULL if an error occured or
1039 if the
{\it wait
} parameter was FALSE and there were no pending
1042 \wxheading{See also
}
1044 \helpref{wxSocketServer::WaitForAccept
}{wxsocketserverwaitforaccept
},
1045 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
1046 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
1047 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}
1052 \membersection{wxSocketServer::AcceptWith
}\label{wxsocketserveracceptwith
}
1054 \func{bool
}{AcceptWith
}{\param{wxSocketBase\&
}{ socket
},
\param{bool
}{ wait = TRUE
}}
1056 Accept an incoming connection using the specified socket object.
1058 \wxheading{Parameters
}
1060 \docparam{socket
}{Socket to be initialized
}
1062 \wxheading{Return value
}
1064 Returns TRUE on success, or FALSE if an error occured or if the
1065 {\it wait
} parameter was FALSE and there were no pending
1068 \helpref{wxSocketServer::WaitForAccept
}{wxsocketserverwaitforaccept
},
1069 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
1070 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
1071 \helpref{wxSocketServer::Accept
}{wxsocketserveraccept
} for a detailed explanation
1076 \membersection{wxSocketServer::WaitForAccept
}\label{wxsocketserverwaitforaccept
}
1078 \func{bool
}{WaitForAccept
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
1080 This function waits for an incoming connection. Use it if you want to call
1081 \helpref{Accept
}{wxsocketserveraccept
} or
\helpref{AcceptWith
}{wxsocketserveracceptwith
}
1082 with
{\it wait
} set to FALSE, to detect when an incoming connection is waiting
1085 \wxheading{Parameters
}
1087 \docparam{seconds
}{Number of seconds to wait.
1088 If -
1, it will wait for the default timeout,
1089 as set with
\helpref{SetTimeout
}{wxsocketbasesettimeout
}.
}
1091 \docparam{millisecond
}{Number of milliseconds to wait.
}
1093 \wxheading{Return value
}
1095 Returns TRUE if an incoming connection arrived, FALSE if the timeout elapsed.
1097 \wxheading{See also
}
1099 \helpref{wxSocketServer::Accept
}{wxsocketserveraccept
},
1100 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}