1 \section{\class{wxSocketBase
}}\label{wxsocketbase
}
3 \wxheading{Derived from
}
5 \helpref{wxEvtHandler
}{wxevthandler
}
7 \wxheading{Include files
}
11 \wxheading{wxSocket errors
}%\label{wxsocketerrs} % Labels don't work on a non-section!
14 \begin{twocollist
}\itemsep=
0pt
15 \twocolitem{{\bf wxSOCKET
\_NOERROR}}{No error happened.
}
16 \twocolitem{{\bf wxSOCKET
\_INVOP}}{Invalid operation.
}
17 \twocolitem{{\bf wxSOCKET
\_IOERR}}{Input/Output error.
}
18 \twocolitem{{\bf wxSOCKET
\_INVADDR}}{Invalid address passed to wxSocket.
}
19 \twocolitem{{\bf wxSOCKET
\_INVSOCK}}{Invalid socket (uninitialized).
}
20 \twocolitem{{\bf wxSOCKET
\_NOHOST}}{No corresponding host.
}
21 \twocolitem{{\bf wxSOCKET
\_INVPORT}}{Invalid port.
}
22 \twocolitem{{\bf wxSOCKET
\_WOULDBLOCK}}{The socket is non-blocking and the operation would block.
}
23 \twocolitem{{\bf wxSOCKET
\_TIMEDOUT}}{The timeout for this operation expired.
}
24 \twocolitem{{\bf wxSOCKET
\_MEMERR}}{Memory exhausted.
}
27 \wxheading{wxSocket events
}
30 \begin{twocollist
}\itemsep=
0pt
31 \twocolitem{{\bf wxSOCKET
\_INPUT}}{Some data has arrived to the socket.
}
32 \twocolitem{{\bf wxSOCKET
\_OUTPUT}}{The socket is ready to be written to.
}
33 \twocolitem{{\bf wxSOCKET
\_CONNECTION}}{Incoming connection arrival (server), or connection establishment (client).
}
34 \twocolitem{{\bf wxSOCKET
\_LOST}}{The connection has been closed.
}
35 \twocolitem{{\bf wxSOCKET
\_MAX\_EVENT}}{This should never happen but the compiler may complain about it.
}
38 A brief note on how to use these events:
40 The
{\bf wxSOCKET
\_INPUT} event will be issued when the incoming queue
41 was empty and new data arrives, but NOT if new data arrives when there
42 was data waiting in the incoming queue.
44 The
{\bf wxSOCKET
\_OUTPUT} event is issued when a socket is first connected
45 with Connect or accepted with Accept, and then, only after an output operation
46 fails because the output buffer was full, and buffer space becomes available
49 The
{\bf wxSOCKET
\_CONNECTION} event is issued when a connection request
50 completes (client) or when a new connection arrives at the pending
51 connections queue (server).
53 The
{\bf wxSOCKET
\_LOST} event is issued when a close indication is
54 received for the socket. This means that the connection broke down or
55 that it was closed by the peer.
57 % ---------------------------------------------------------------------------
59 % ---------------------------------------------------------------------------
60 \wxheading{Event handling
}
62 To process events from a socket, use the following event handler macro to direct
63 input to member functions that take a
\helpref{wxSocketEvent
}{wxsocketevent
} argument.
66 \begin{twocollist
}\itemsep=
0pt
67 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{A socket event occured.
}
70 % ---------------------------------------------------------------------------
72 % ---------------------------------------------------------------------------
75 \helpref{wxSocketEvent
}{wxsocketevent
}\\
76 \helpref{wxSocketClient
}{wxsocketclient
}\\
77 \helpref{wxSocketServer
}{wxsocketserver
}
79 % ---------------------------------------------------------------------------
81 % ---------------------------------------------------------------------------
82 \latexignore{\rtfignore{\wxheading{Members
}}}
84 \membersection{wxSocketBase::wxSocketBase
}
86 \func{}{wxSocketBase
}{\void}
88 Default constructor. Don't use it; use
\helpref{wxSocketClient
}{wxsocketclient
}
89 or
\helpref{wxSocketServer
}{wxsocketserver
}.
91 \membersection{wxSocketBase::
\destruct{wxSocketBase
}}
93 \func{}{\destruct{wxSocketBase
}}{\void}
95 Destroys the wxSocketBase object.
97 % ---------------------------------------------------------------------------
99 % ---------------------------------------------------------------------------
105 \membersection{wxSocketBase::SetFlags
}\label{wxsocketbasesetflags
}
107 \func{void
}{SetFlags
}{\param{wxSocketBase::wxSockFlags
}{ flags
}}
110 \begin{twocollist
}\itemsep=
0pt
111 \twocolitem{{\bf wxSOCKET
\_NONE}}{Normal functionnality.
}
112 \twocolitem{{\bf wxSOCKET
\_NOWAIT}}{Get the available data in the input queue and return immediately.
}
113 \twocolitem{{\bf wxSOCKET
\_WAITALL}}{Wait for all required data unless an error occurs.
}
114 \twocolitem{{\bf wxSOCKET
\_BLOCK}}{Block the GUI (do not wxYield) while reading / writing data.
}
117 A brief overview on how to use these flags follows.
119 If no flag is specified (this is the same as
{\bf wxSOCKET
\_NONE}),
120 IO calls will return after some data has been read or written, even
121 when the transfer might not be complete. This is the same as issuing
122 exactly one blocking low-level call to recv() or send(). Note that
123 blocking here refers to when the function returns, not to whether
124 the GUI blocks during this time.
126 If
{\bf wxSOCKET
\_NOWAIT} is specified, IO calls will return immediately.
127 Read operations will retrieve only available data. Write operations will
128 write as much data as possible, depending on how much space is available
129 in the output buffer. This is the same as issuing exactly one nonblocking
130 low-level call to recv() or send(). Note that nonblocking here refers to
131 when the function returns, not to whether the GUI blocks during this time.
133 If
{\bf wxSOCKET
\_WAITALL} is specified, IO calls won't return until ALL
134 the data has been read or written (or until an error occurs), blocking if
135 necessary, and issuing several low level calls if necessary. This is the
136 same as having a loop which makes as many blocking low-level calls to
137 recv() or send() as needed so as to transfer all the data. Note that
138 "blocking" here refers to when the function returns, not to whether
139 the GUI blocks during this time.
141 The
{\bf wxSOCKET
\_BLOCK} controls whether the GUI blocks during IO
142 operations. If this flag is not used, then the application must take
143 extra care to avoid unwanted reentrance.
147 {\bf wxSOCKET
\_NONE} will try to read SOME data, no matter how much.
148 {\bf wxSOCKET
\_NOWAIT} will always return immediately, even if it cannot
149 read or write ANY data.
150 {\bf wxSOCKET
\_WAITALL} will only return when it has read or written ALL
152 {\bf wxSOCKET
\_BLOCK} has nothing to do with the previous flags and
153 it control whether the GUI blocks.
158 \membersection{wxSocketBase::SetNotify
}\label{wxsocketbasesetnotify
}
160 \func{void
}{SetNotify
}{\param{wxSocketEventFlags
}{ flags
}}
162 SetNotify specifies which socket events are to be sent to the event handler.
163 The
{\it flags
} parameter is a combination of flags ORed toghether. The
164 following flags can be used:
167 \begin{twocollist
}\itemsep=
0pt
168 \twocolitem{{\bf wxSOCKET
\_INPUT\_FLAG}}{to receive wxSOCKET
\_INPUT}
169 \twocolitem{{\bf wxSOCKET
\_OUTPUT\_FLAG}}{to receive wxSOCKET
\_OUTPUT}
170 \twocolitem{{\bf wxSOCKET
\_CONNECTION\_FLAG}}{to receive wxSOCKET
\_CONNECTION}
171 \twocolitem{{\bf wxSOCKET
\_LOST\_FLAG}}{to receive wxSOCKET
\_LOST}
176 sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
178 In this example, the user will be notified about incoming socket data and
179 whenever the connection is closed.
181 For more information on socket events see
\helpref{wxSocket events
}{wxsocketbase
}.
186 \membersection{wxSocketBase::SetTimeout
}{wxsocketbasesettimeout
}
188 \func{void
}{SetTimeout
}{\param{int
}{seconds
}}
190 This function sets the default socket timeout in seconds. This
191 timeout applies to IO calls and also to Wait functions if you
192 don't specify a wait interval. If you never use SetTimeout, the
193 default timeout will be
10 minutes.
198 \membersection{wxSocketBase::Notify
}\label{wxsocketbasenotify
}
200 \func{void
}{Notify
}{\param{bool
}{ notify
}}
202 Notify will enable (notify is TRUE) or disable (notify is FALSE) the propagation
209 \membersection{wxSocketBase::Ok
}\label{wxsocketbaseok
}
211 \constfunc{bool
}{Ok
}{\void}
213 Returns TRUE if the socket is initialized and ready and FALSE in other
216 \membersection{wxSocketBase::Error
}\label{wxsocketbaseerror
}
218 \constfunc{bool
}{Error
}{\void}
220 Returns TRUE if an error occured in the last IO operation.
222 The following operations update the Error() status:
223 Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
225 \membersection{wxSocketBase::IsConnected
}\label{wxsocketbaseconnected
}
227 \constfunc{bool
}{IsConnected
}{\void}
229 Returns TRUE if the socket is connected.
231 \membersection{wxSocketBase::IsData
}\label{wxsocketbaseisdata
}
233 \constfunc{bool
}{IsData
}{\void}
235 Returns TRUE if there is data available to be read.
237 \membersection{wxSocketBase::IsDisconnected
}\label{wxsocketbasedisconnected
}
239 \constfunc{bool
}{IsDisconnected
}{\void}
241 Returns TRUE if the socket is disconnected.
243 \membersection{wxSocketBase::IsNoWait
}\label{wxsocketbasenowait
}
245 \constfunc{bool
}{IsNoWait
}{\void}
247 Returns TRUE if the socket mustn't wait.
249 \membersection{wxSocketBase::LastCount
}\label{wxsocketbaselastcount
}
251 \constfunc{wxUint32
}{LastCount
}{\void}
253 Returns the number of bytes read or written by the last IO call.
255 The following operations update the LastCount() value:
256 Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
258 \membersection{wxSocketBase::LastError
}\label{wxsocketbaselasterror
}
260 \constfunc{wxSocketError
}{LastError
}{\void}
262 Returns the last wxSocket error. See
\helpref{wxSocket errors
}{wxsocketbase
}.
264 Please note that this function merely returns the last error code,
265 but it should not be used to determine if an error has occured (this
266 is because successful operations do not change tha LastError value).
267 Use Error, instead of LastError, to determine if the last IO call
268 failed. If Error returns TRUE, use LastError to discover the
271 % ---------------------------------------------------------------------------
273 % ---------------------------------------------------------------------------
277 \membersection{wxSocketBase::Peek
}\label{wxsocketbasepeek
}
279 \func{wxSocketBase\&
}{Peek
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
281 This function peeks a buffer of
{\it nbytes
} bytes from the socket. Peeking a buffer
282 doesn't delete it from the system socket in-queue.
284 Use LastCount to verify the number of bytes actually peeked.
286 Use Error to determine if the operation succeeded.
288 \wxheading{Parameters
}
290 \docparam{buffer
}{Buffer where to put peeked data.
}
292 \docparam{nbytes
}{Number of bytes.
}
294 \wxheading{Return value
}
296 Returns a reference to the current object.
298 \wxheading{Remark/Warning
}
300 The exact behaviour of wxSocketBase::Peek() depends on the combination
301 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
305 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
306 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}\\
307 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
308 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
313 \membersection{wxSocketBase::Read
}\label{wxsocketbaseread
}
315 \func{wxSocketBase\&
}{Read
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
317 This function reads a buffer of
{\it nbytes
} bytes from the socket.
319 Use LastCount to verify the number of bytes actually read.
321 Use Error to determine if the operation succeeded.
323 \wxheading{Parameters
}
325 \docparam{buffer
}{Buffer where to put read data.
}
327 \docparam{nbytes
}{Number of bytes.
}
329 \wxheading{Return value
}
331 Returns a reference to the current object.
333 \wxheading{Remark/Warning
}
335 The exact behaviour of wxSocketBase::Read() depends on the combination
336 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
340 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
341 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}\\
342 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
343 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
348 \membersection{wxSocketBase::Write
}\label{wxsocketbasewrite
}
350 \func{wxSocketBase\&
}{Write
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
352 This function writes a buffer of
{\it nbytes
} bytes to the socket.
354 Use LastCount to verify the number of bytes actually written.
356 Use Error to determine if the operation succeeded.
358 \wxheading{Parameters
}
360 \docparam{buffer
}{Buffer with the data to be sent.
}
362 \docparam{nbytes
}{Number of bytes.
}
364 \wxheading{Return value
}
366 Returns a reference to the current object.
368 \wxheading{Remark/Warning
}
370 The exact behaviour of wxSocketBase::Write() depends on the combination
371 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
375 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
376 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}\\
377 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
378 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
383 \membersection{wxSocketBase::WriteMsg
}\label{wxsocketbasewritemsg
}
385 \func{wxSocketBase\&
}{WriteMsg
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
387 This function writes a buffer of
{\it nbytes
} bytes from the socket, but it
388 writes a short header before so that ReadMsg can alloc the right size for
389 the buffer. So, a buffer sent with WriteMsg
{\bf must
} be read with ReadMsg.
390 This function always waits for the entire buffer to be sent, unless an
393 Use LastCount to verify the number of bytes actually written.
395 Use Error to determine if the operation succeeded.
397 \wxheading{Parameters
}
399 \docparam{buffer
}{Buffer with the data to be sent.
}
401 \docparam{nbytes
}{Number of bytes.
}
403 \wxheading{Return value
}
405 Returns a reference to the current object.
407 \wxheading{Remark/Warning
}
409 wxSocketBase::WriteMsg() will behave as if the wxSOCKET_WAITALL flag was always set
410 and it will always ignore the wxSOCKET_NOWAIT flag. The exact behaviour of WriteMsg
411 depends on the wxSOCKET_BLOCK flag. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
415 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
416 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}\\
417 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
418 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}\\
419 \helpref{wxSocketBase::ReadMsg
}{wxsocketbasereadmsg
}
424 \membersection{wxSocketBase::ReadMsg
}\label{wxsocketbasereadmsg
}
426 \func{wxSocketBase\&
}{ReadMsg
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
428 This function reads a buffer sent by WriteMsg on a socket. If the buffer passed
429 to the function isn't big enough, the remaining bytes will be discarded. This
430 function always waits for the buffer to be entirely filled, unless an error occurs.
432 Use LastCount to verify the number of bytes actually read.
434 Use Error to determine if the operation succeeded.
436 \wxheading{Parameters
}
438 \docparam{buffer
}{Buffer where to put read data.
}
440 \docparam{nbytes
}{Number of bytes allocated for the buffer.
}
442 \wxheading{Return value
}
444 Returns a reference to the current object.
446 \wxheading{Remark/Warning
}
448 wxSocketBase::ReadMsg() will behave as if the wxSOCKET_WAITALL flag was always set
449 and it will always ignore the wxSOCKET_NOWAIT flag. The exact behaviour of ReadMsg
450 depends on the wxSOCKET_SPEED flag. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
454 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
455 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}\\
456 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
457 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}\\
458 \helpref{wxSocketBase::WriteMsg
}{wxsocketbasewritemsg
}
463 \membersection{wxSocketBase::Unread
}\label{wxsocketbaseunread
}
465 \func{wxSocketBase\&
}{Unread
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
467 This function unreads a buffer. That is, the data in the buffer is put back
468 in the incoming queue. This function is not affected by wxSocket flags.
470 If you use LastCount, it will always return
{\it nbytes
}.
472 If you use Error, it will always return FALSE.
474 \wxheading{Parameters
}
476 \docparam{buffer
}{Buffer to be unread.
}
478 \docparam{nbytes
}{Number of bytes.
}
480 \wxheading{Return value
}
482 Returns a reference to the current object.
486 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
}\\
487 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
}\\
488 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
493 \membersection{wxSocketBase::Discard
}\label{wxsocketbasediscard
}
495 \func{wxSocketBase\&
}{Discard
}{\void}
497 This function simply deletes all bytes in the incoming queue. This function
498 doesn't wait. That is, it will behave as if the wxSOCKET_NOWAIT flag was set. The
499 wxSOCKET_SPEED and wxSOCKET_WAITALL flags have no effect on this function.
501 Use LastCount to see the number of bytes discarded.
503 If you use Error, it will always return FALSE.
505 % ---------------------------------------------------------------------------
507 % ---------------------------------------------------------------------------
508 \membersection{wxSocketBase::Wait
}\label{wxsocketbasewait
}
510 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
512 This function waits until one of the following conditions is true: there
513 is data available for reading; the output buffer is empty (you can send
514 new data); the connection has been lost; an incoming connection arrived
515 (only for servers); a connection request has completed (only for clients).
517 \wxheading{Parameters
}
519 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
521 \docparam{millisecond
}{Number of milliseconds to wait.
}
523 \wxheading{Return value
}
525 Returns TRUE if an event occured, FALSE if the timeout was reached.
529 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
}\\
530 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
}\\
531 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
536 \membersection{wxSocketBase::WaitForRead
}\label{wxsocketbasewaitforread
}
538 \func{bool
}{WaitForRead
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
540 This function waits until there is data available to be read.
542 \wxheading{Parameters
}
544 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
546 \docparam{millisecond
}{Number of milliseconds to wait.
}
548 \wxheading{Return value
}
550 Returns TRUE if there is data to be read, FALSE if the timeout was reached.
554 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
}\\
555 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
}\\
556 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
561 \membersection{wxSocketBase::WaitForWrite
}\label{wxsocketbasewaitforwrite
}
563 \func{bool
}{WaitForWrite
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
565 This function waits until you can write to the socket.
567 \wxheading{Parameters
}
569 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
571 \docparam{millisecond
}{Number of milliseconds to wait.
}
573 \wxheading{Return value
}
575 Returns TRUE if you can write to the socket, FALSE if the timeout was reached.
579 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
}\\
580 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
}\\
581 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
586 \membersection{wxSocketBase::WaitForLost
}\label{wxsocketbasewaitforlost
}
588 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
590 This function waits until the connection is lost. This may happen if the
591 peer closes the connection or if the connection breaks.
593 \wxheading{Parameters
}
595 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
597 \docparam{millisecond
}{Number of milliseconds to wait.
}
599 \wxheading{Return value
}
601 Returns TRUE if the connection was lost, FALSE if the timeout was reached.
605 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
}\\
606 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
}\\
607 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
609 % ---------------------------------------------------------------------------
611 % ---------------------------------------------------------------------------
616 \membersection{wxSocketBase::RestoreState
}\label{wxsocketbaserestorestate
}
618 \func{void
}{RestoreState
}{\void}
620 This function restores the previous state of the socket, as saved
623 Calls to SaveState / RestoreState can be nested.
627 \helpref{wxSocketBase::SaveState
}{wxsocketbasesavestate
}
632 \membersection{wxSocketBase::SaveState
}\label{wxsocketbasesavestate
}
634 \func{void
}{SaveState
}{\void}
636 This function saves the current state of the socket object in a stack:
637 actually it saves all flags (those set with SetFlags, SetNotify, Notfy)
638 and the state of the asynchronous callbacks (Callback, CallbackData).
640 Calls to SaveState / RestoreState can be nested.
644 \helpref{wxSocketBase::RestoreState
}{wxsocketbaserestorestate
}
649 \membersection{wxSocketBase::GetLocal
}{wxsocketbasegetlocal
}
651 \constfunc{bool
}{GetLocal
}{\param{wxSockAddress\&
}{addr_man
}}
653 This function returns the local address field of the socket. The local
654 address field contains the complete local address of the socket (local
655 address, local port, ...).
657 \wxheading{Return value
}
659 It returns TRUE if no errors happened, FALSE otherwise.
664 \membersection{wxSocketBase::GetPeer
}{wxsocketbasegetlocal
}
666 \constfunc{bool
}{GetPeer
}{\param{wxSockAddress\&
}{addr_man
}}
668 This function returns the peer address field of the socket. The peer
669 address field contains the complete peer host address of the socket
670 (address, port, ...).
672 \wxheading{Return value
}
674 It returns TRUE if no errors happened, FALSE otherwise.
676 % ---------------------------------------------------------------------------
678 % ---------------------------------------------------------------------------
679 \membersection{wxSocketBase::SetEventHandler
}\label{wxsocketbaseseteventhandler
}
681 \func{void
}{SetEventHandler
}{\param{wxEvtHandler\&
}{ evt
\_hdlr},
\param{int
}{ id = -
1}}
683 Sets an event handler to be called when a socket event occurs. The handler
684 will be called for those events for which notification is enabled with
685 SetNotify and Notify.
687 You can also specify a C callback to be called when an event occurs. See
688 Callback and CallbackData.
690 \wxheading{Parameters
}
692 \docparam{evt
\_hdlr}{Specifies the event handler you want to use.
}
694 \docparam{id
}{The id of socket event.
}
698 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
}\\
699 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}\\
700 \helpref{wxSocketEvent
}{wxsocketevent
}\\
701 \helpref{wxEvtHandler
}{wxevthandler
}\\
702 \helpref{wxSocketBase::Callback
}{wxsocketbasecallback
}\\
703 \helpref{wxSocketBase::CallbackData
}{wxsocketbasecallbackdata
}
705 \membersection{wxSocketBase::Callback
}\label{wxsocketbasecallback
}
707 \func{wxSocketBase::wxSockCbk
}{Callback
}{\param{wxSocketBase::wxSockCbk
}{ callback
}}
709 You can setup a C callback to be called when an event occurs. The callback
710 will be called only for those events for which notification has been enabled
711 with Notify and SetNotify. The prototype of the callback must be as follows:
714 void SocketCallback(wxSocketBase& sock,wxSocketNotify evt,char *cdata);
717 The first parameter is a reference to the socket object in which the event
718 occured. The second parameter tells you which event occured. (See
\helpref{wxSocket events
}{wxsocketbase
}).
719 The third parameter is the user data you specified using
\helpref{CallbackData
}{wxsocketcallbackdata
}.
721 \wxheading{Return value
}
723 A pointer to the previous callback.
727 \helpref{wxSocketBase::CallbackData
}{wxsocketbasecallbackdata
}\\
728 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
}\\
729 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
731 \membersection{wxSocketBase::CallbackData
}\label{wxsocketbasecallbackdata
}
733 \func{char *
}{CallbackData
}{\param{char *
}{cdata
}}
735 This function sets the the user data which will be passed to a
\helpref{C callback
}{wxsocketbasecallback
}.
737 \wxheading{Return value
}
739 A pointer to the previous user data.
741 \helpref{wxSocketBase::Callback
}{wxsocketbasecallback
}\\
742 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
}\\
743 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
745 % ---------------------------------------------------------------------------
746 % CLASS wxSocketClient
747 % ---------------------------------------------------------------------------
748 \section{\class{wxSocketClient
}}\label{wxsocketclient
}
750 \wxheading{Derived from
}
752 \helpref{wxSocketBase
}{wxsocketbase
}
754 \wxheading{Include files
}
758 % ---------------------------------------------------------------------------
760 % ---------------------------------------------------------------------------
764 \membersection{wxSocketClient::wxSocketClient
}
766 \func{}{wxSocketClient
}{\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
768 Constructs a new wxSocketClient.
770 \wxheading{Parameters
}
772 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
777 \membersection{wxSocketClient::
\destruct{wxSocketClient
}}
779 \func{}{\destruct{wxSocketClient
}}{\void}
781 Destroys a wxSocketClient object.
786 \membersection{wxSocketClient::Connect
}\label{wxsocketclientconnect
}
788 \func{bool
}{Connect
}{\param{wxSockAddress\&
}{ address
},
\param{bool
}{ wait = TRUE
}}
790 Connects to a server using the specified address.
792 If
{\it wait
} is TRUE, Connect will wait until the connection completes and
793 the socket is ready to send or receive data, or until an event occurs.
794 {\bf Warning !
} This will block the GUI.
796 If
{\it wait
} is FALSE, Connect will try to establish the connection and
797 return immediately, without blocking the GUI. When used this way, even if
798 Connect returns FALSE, the connection request can be completed later.
799 To detect this, use WaitConnection, or watch "connection" events (for
800 succesful establishment) and "lost" events (for connection failure)
803 \wxheading{Parameters
}
805 \docparam{address
}{Address of the server.
}
807 \docparam{wait
}{If true, waits for the connection to be ready.
}
809 \wxheading{Return value
}
811 Returns TRUE if the connection is established and no error occurs.
813 If
{\it wait
} was TRUE, and Connect returns FALSE, an error occured
814 and the connection failed.
816 If
{\it wait
} was FALSE, and Connect returns FALSE, you should still
817 be prepared to handle the completion of this connection request, either
818 with WaitOnConnect or by watching "connection" and "lost" events.
822 \helpref{wxSocketClient::WaitOnConnect
}{wxsocketclientwaitonconnect
}\\
823 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
}\\
824 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
829 \membersection{wxSocketClient::WaitOnConnect
}\label{wxsocketclientwaitonconnect
}
831 \func{bool
}{WaitOnConnect
}{\param{long
}{ seconds = -
1},
\param{long
}{ milliseconds =
0}}
833 Wait until the connection is succesfully established or until it fails.
834 Use this function after a call to Connect with
{\it wait
} set to FALSE.
836 \wxheading{Parameters
}
838 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
840 \docparam{millisecond
}{Number of milliseconds to wait.
}
842 \wxheading{Return value
}
844 If the connection is succesfully established, it returns TRUE.
846 If the timeout expires, or if the connection fails, it returns FALSE.
850 \helpref{wxSocketClient::Connect
}{wxsocketclientconnect
}
852 % ---------------------------------------------------------------------------
853 % CLASS: wxSocketEvent
854 % ---------------------------------------------------------------------------
855 \section{\class{wxSocketEvent
}}\label{wxsocketevent
}
857 This event class contains information about socket events.
859 \wxheading{Derived from
}
861 \helpref{wxEvent
}{wxevent
}
863 \wxheading{Include files
}
867 \wxheading{Event table macros
}
869 To process a socket event, use these event handler macros to direct input to member
870 functions that take a wxSocketEvent argument.
873 \begin{twocollist
}\itemsep=
0pt
874 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{Process a socket event, supplying the member function.
}
878 A brief note on how to use events.
879 The wxSOCKET_INPUT event is generated when the
883 \helpref{wxSocketBase
}{wxsocketbase
},
\rtfsp
884 \helpref{wxSocketClient
}{wxsocketclient
},
\rtfsp
885 \helpref{wxSocketServer
}{wxsocketserver
}
887 \latexignore{\rtfignore{\wxheading{Members
}}}
889 \membersection{wxSocketEvent::wxSocketEvent
}
891 \func{}{wxSocketEvent
}{\param{int
}{ id =
0}}
895 \membersection{wxSocketEvent::SocketEvent
}\label{wxsocketeventsocketevent
}
897 \constfunc{wxSocketNotify
}{SocketEvent
}{\void}
899 Returns the socket event type.
901 % ---------------------------------------------------------------------------
902 % CLASS: wxSocketServer
903 % ---------------------------------------------------------------------------
904 \section{\class{wxSocketServer
}}\label{wxsocketserver
}
906 \wxheading{Derived from
}
908 \helpref{wxSocketBase
}{wxsocketbase
}
910 \wxheading{Include files
}
914 % ---------------------------------------------------------------------------
916 % ---------------------------------------------------------------------------
917 \latexignore{\rtfignore{\wxheading{Members
}}}
922 \membersection{wxSocketServer::wxSocketServer
}\label{wxsocketserverconstr
}
924 \func{}{wxSocketServer
}{\param{wxSockAddress\&
}{ address
},
\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
926 Constructs a new wxSocketServer.
928 \wxheading{Parameters
}
930 \docparam{address
}{Specifies the local address for the server (e.g. port number).
}
932 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
937 \membersection{wxSocketServer::
\destruct{wxSocketServer
}}
939 \func{}{\destruct{wxSocketServer
}}{\void}
941 Destroys a wxSocketServer object (it doesn't close the accepted connections).
946 \membersection{wxSocketServer::Accept
}
948 \func{wxSocketBase *
}{Accept
}{\param{bool
}{ wait = TRUE
}}
950 Creates a new object wxSocketBase and accepts an incoming connection.
952 If
{\it wait
} is TRUE and there are no pending connections to be
953 accepted, it will wait for the next incoming connection to arrive.
954 {\bf Warning !
} This will block the GUI.
956 If
{\it wait
} is FALSE, it will try to accept a pending connection
957 if there is one, but it will always return immediately without
958 blocking the GUI. If you want to use Accept in this way, you can
959 either check for incoming connections with WaitForAccept or watch
960 "connection" events, then call Accept once you know that there is
961 an incoming connection waiting to be accepted.
963 \wxheading{Return value
}
965 Returns an opened socket connection, or NULL if an error occured or
966 if the
{\it wait
} parameter was FALSE and there were no pending
971 \helpref{wxSocketServer::WaitForAccept
}{wxsocketbasewaitforaccept
}\\
972 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
}\\
973 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}\\
974 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}
979 \membersection{wxSocketServer::AcceptWith
}\label{wxsocketserveracceptwith
}
981 \func{bool
}{AcceptWith
}{\param{wxSocketBase\&
}{ socket
},
\param{bool
}{ wait = TRUE
}}
983 Accept an incoming connection using the specified socket object.
984 This is useful when someone wants to inherit wxSocketBase.
986 \wxheading{Parameters
}
988 \docparam{socket
}{Socket to be initialized
}
990 \wxheading{Return value
}
992 Returns TRUE on success, or FALSE if an error occured or if the
993 {\it wait
} parameter was FALSE and there were no pending
996 \helpref{wxSocketServer::WaitForAccept
}{wxsocketbasewaitforaccept
}\\
997 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
}\\
998 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}\\
999 \helpref{wxSocketServer::Accept
}{wxsocketserveraccept
} for a detailed explanation
1005 \membersection{wxSocketServer::WaitForAccept
}\label{wxsocketserverwaitforaccept
}
1007 \func{bool
}{WaitForAccept
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
1009 This function waits for an incoming connection. Use it if you want to call
1010 Accept or AcceptWith with
{\it wait
} set to FALSE, to detect when an incoming
1011 connection is waiting to be accepted.
1013 \wxheading{Parameters
}
1015 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
1017 \docparam{millisecond
}{Number of milliseconds to wait.
}
1019 \wxheading{Return value
}
1021 Returns TRUE if an incoming connection arrived, FALSE if the timeout expired.
1023 \wxheading{See also
}
1025 \helpref{wxSocketServer::Accept
}{wxsocketserveraccept
}\\
1026 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}