1 \section{\class{wxSocketBase
}}\label{wxsocketbase
}
3 \wxheading{Derived from
}
5 \helpref{wxEvtHandler
}{wxevthandler
}
7 \wxheading{Include files
}
11 \wxheading{wxSocket errors
}
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} flag controls whether the GUI blocks during
142 IO 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.
149 {\bf wxSOCKET
\_NOWAIT} will always return immediately, even if it cannot
150 read or write ANY data.
152 {\bf wxSOCKET
\_WAITALL} will only return when it has read or written ALL
155 {\bf wxSOCKET
\_BLOCK} has nothing to do with the previous flags and
156 it controls whether the GUI blocks.
161 \membersection{wxSocketBase::SetNotify
}\label{wxsocketbasesetnotify
}
163 \func{void
}{SetNotify
}{\param{wxSocketEventFlags
}{ flags
}}
165 SetNotify specifies which socket events are to be sent to the event handler.
166 The
{\it flags
} parameter is a combination of flags ORed toghether. The
167 following flags can be used:
170 \begin{twocollist
}\itemsep=
0pt
171 \twocolitem{{\bf wxSOCKET
\_INPUT\_FLAG}}{to receive wxSOCKET
\_INPUT}
172 \twocolitem{{\bf wxSOCKET
\_OUTPUT\_FLAG}}{to receive wxSOCKET
\_OUTPUT}
173 \twocolitem{{\bf wxSOCKET
\_CONNECTION\_FLAG}}{to receive wxSOCKET
\_CONNECTION}
174 \twocolitem{{\bf wxSOCKET
\_LOST\_FLAG}}{to receive wxSOCKET
\_LOST}
180 sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
183 In this example, the user will be notified about incoming socket data and
184 whenever the connection is closed.
186 For more information on socket events see
\helpref{wxSocket events
}{wxsocketbase
}.
191 \membersection{wxSocketBase::SetTimeout
}\label{wxsocketbasesettimeout
}
193 \func{void
}{SetTimeout
}{\param{int
}{seconds
}}
195 This function sets the default socket timeout in seconds. This
196 timeout applies to IO calls and also to Wait functions if you
197 don't specify a wait interval. If you never use SetTimeout, the
198 default timeout will be
10 minutes.
203 \membersection{wxSocketBase::Notify
}\label{wxsocketbasenotify
}
205 \func{void
}{Notify
}{\param{bool
}{ notify
}}
207 Notify will enable (notify is TRUE) or disable (notify is FALSE) the propagation
214 \membersection{wxSocketBase::Ok
}\label{wxsocketbaseok
}
216 \constfunc{bool
}{Ok
}{\void}
218 Returns TRUE if the socket is initialized and ready and FALSE in other
221 \membersection{wxSocketBase::Error
}\label{wxsocketbaseerror
}
223 \constfunc{bool
}{Error
}{\void}
225 Returns TRUE if an error occured in the last IO operation.
227 The following operations update the Error() status:
228 Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
230 \membersection{wxSocketBase::IsConnected
}\label{wxsocketbaseconnected
}
232 \constfunc{bool
}{IsConnected
}{\void}
234 Returns TRUE if the socket is connected.
236 \membersection{wxSocketBase::IsData
}\label{wxsocketbaseisdata
}
238 \constfunc{bool
}{IsData
}{\void}
240 Returns TRUE if there is data available to be read.
242 \membersection{wxSocketBase::IsDisconnected
}\label{wxsocketbasedisconnected
}
244 \constfunc{bool
}{IsDisconnected
}{\void}
246 Returns TRUE if the socket is disconnected.
248 \membersection{wxSocketBase::IsNoWait
}\label{wxsocketbasenowait
}
250 \constfunc{bool
}{IsNoWait
}{\void}
252 Returns TRUE if the socket mustn't wait.
254 \membersection{wxSocketBase::LastCount
}\label{wxsocketbaselastcount
}
256 \constfunc{wxUint32
}{LastCount
}{\void}
258 Returns the number of bytes read or written by the last IO call.
260 The following operations update the LastCount() value:
261 Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
263 \membersection{wxSocketBase::LastError
}\label{wxsocketbaselasterror
}
265 \constfunc{wxSocketError
}{LastError
}{\void}
267 Returns the last wxSocket error. See
\helpref{wxSocket errors
}{wxsocketbase
}.
269 Please note that this function merely returns the last error code,
270 but it should not be used to determine if an error has occured (this
271 is because successful operations do not change tha LastError value).
272 Use Error, instead of LastError, to determine if the last IO call
273 failed. If Error returns TRUE, use LastError to discover the
276 % ---------------------------------------------------------------------------
278 % ---------------------------------------------------------------------------
282 \membersection{wxSocketBase::Peek
}\label{wxsocketbasepeek
}
284 \func{wxSocketBase\&
}{Peek
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
286 This function peeks a buffer of
{\it nbytes
} bytes from the socket. Peeking a buffer
287 doesn't delete it from the system socket in-queue.
289 Use LastCount to verify the number of bytes actually peeked.
291 Use Error to determine if the operation succeeded.
293 \wxheading{Parameters
}
295 \docparam{buffer
}{Buffer where to put peeked data.
}
297 \docparam{nbytes
}{Number of bytes.
}
299 \wxheading{Return value
}
301 Returns a reference to the current object.
303 \wxheading{Remark/Warning
}
305 The exact behaviour of wxSocketBase::Peek() depends on the combination
306 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
310 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
311 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
312 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
313 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
318 \membersection{wxSocketBase::Read
}\label{wxsocketbaseread
}
320 \func{wxSocketBase\&
}{Read
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
322 This function reads a buffer of
{\it nbytes
} bytes from the socket.
324 Use LastCount to verify the number of bytes actually read.
326 Use Error to determine if the operation succeeded.
328 \wxheading{Parameters
}
330 \docparam{buffer
}{Buffer where to put read data.
}
332 \docparam{nbytes
}{Number of bytes.
}
334 \wxheading{Return value
}
336 Returns a reference to the current object.
338 \wxheading{Remark/Warning
}
340 The exact behaviour of wxSocketBase::Read() depends on the combination
341 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
345 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
346 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
347 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
348 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
353 \membersection{wxSocketBase::Write
}\label{wxsocketbasewrite
}
355 \func{wxSocketBase\&
}{Write
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
357 This function writes a buffer of
{\it nbytes
} bytes to the socket.
359 Use LastCount to verify the number of bytes actually written.
361 Use Error to determine if the operation succeeded.
363 \wxheading{Parameters
}
365 \docparam{buffer
}{Buffer with the data to be sent.
}
367 \docparam{nbytes
}{Number of bytes.
}
369 \wxheading{Return value
}
371 Returns a reference to the current object.
373 \wxheading{Remark/Warning
}
375 The exact behaviour of wxSocketBase::Write() depends on the combination
376 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
380 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
381 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
382 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
383 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
388 \membersection{wxSocketBase::WriteMsg
}\label{wxsocketbasewritemsg
}
390 \func{wxSocketBase\&
}{WriteMsg
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
392 This function writes a buffer of
{\it nbytes
} bytes from the socket, but it
393 writes a short header before so that ReadMsg can alloc the right size for
394 the buffer. So, a buffer sent with WriteMsg
{\bf must
} be read with ReadMsg.
395 This function always waits for the entire buffer to be sent, unless an
398 Use LastCount to verify the number of bytes actually written.
400 Use Error to determine if the operation succeeded.
402 \wxheading{Parameters
}
404 \docparam{buffer
}{Buffer with the data to be sent.
}
406 \docparam{nbytes
}{Number of bytes.
}
408 \wxheading{Return value
}
410 Returns a reference to the current object.
412 \wxheading{Remark/Warning
}
414 wxSocketBase::WriteMsg() will behave as if the wxSOCKET
\_WAITALL flag was always set
415 and it will always ignore the wxSOCKET
\_NOWAIT flag. The exact behaviour of WriteMsg
416 depends on the wxSOCKET
\_BLOCK flag. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
420 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
421 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
422 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
423 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
},
424 \helpref{wxSocketBase::ReadMsg
}{wxsocketbasereadmsg
}
429 \membersection{wxSocketBase::ReadMsg
}\label{wxsocketbasereadmsg
}
431 \func{wxSocketBase\&
}{ReadMsg
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
433 This function reads a buffer sent by WriteMsg on a socket. If the buffer passed
434 to the function isn't big enough, the remaining bytes will be discarded. This
435 function always waits for the buffer to be entirely filled, unless an error occurs.
437 Use LastCount to verify the number of bytes actually read.
439 Use Error to determine if the operation succeeded.
441 \wxheading{Parameters
}
443 \docparam{buffer
}{Buffer where to put read data.
}
445 \docparam{nbytes
}{Number of bytes allocated for the buffer.
}
447 \wxheading{Return value
}
449 Returns a reference to the current object.
451 \wxheading{Remark/Warning
}
453 wxSocketBase::ReadMsg() will behave as if the wxSOCKET
\_WAITALL flag was always set
454 and it will always ignore the wxSOCKET
\_NOWAIT flag. The exact behaviour of ReadMsg
455 depends on the wxSOCKET
\_BLOCK flag. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
459 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
460 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
461 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
462 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
},
463 \helpref{wxSocketBase::WriteMsg
}{wxsocketbasewritemsg
}
468 \membersection{wxSocketBase::Unread
}\label{wxsocketbaseunread
}
470 \func{wxSocketBase\&
}{Unread
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
472 This function unreads a buffer. That is, the data in the buffer is put back
473 in the incoming queue. This function is not affected by wxSocket flags.
475 If you use LastCount, it will always return
{\it nbytes
}.
477 If you use Error, it will always return FALSE.
479 \wxheading{Parameters
}
481 \docparam{buffer
}{Buffer to be unread.
}
483 \docparam{nbytes
}{Number of bytes.
}
485 \wxheading{Return value
}
487 Returns a reference to the current object.
491 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
492 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
493 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
498 \membersection{wxSocketBase::Discard
}\label{wxsocketbasediscard
}
500 \func{wxSocketBase\&
}{Discard
}{\void}
502 This function simply deletes all bytes in the incoming queue. This function
503 doesn't wait. That is, it will behave as if the wxSOCKET
\_NOWAIT flag was set. The
504 wxSOCKET
\_BLOCK and wxSOCKET
\_WAITALL flags have no effect on this function.
506 Use LastCount to see the number of bytes discarded.
508 If you use Error, it will always return FALSE.
510 % ---------------------------------------------------------------------------
512 % ---------------------------------------------------------------------------
513 \membersection{wxSocketBase::Wait
}\label{wxsocketbasewait
}
515 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
517 This function waits until one of the following conditions is true: there
518 is data available for reading; the output buffer is empty (you can send
519 new data); the connection has been lost; an incoming connection arrived
520 (only for servers); a connection request has completed (only for clients).
522 \wxheading{Parameters
}
524 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
526 \docparam{millisecond
}{Number of milliseconds to wait.
}
528 \wxheading{Return value
}
530 Returns TRUE if an event occured, FALSE if the timeout was reached.
534 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
535 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
536 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
541 \membersection{wxSocketBase::WaitForRead
}\label{wxsocketbasewaitforread
}
543 \func{bool
}{WaitForRead
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
545 This function waits until there is data available to be read.
547 \wxheading{Parameters
}
549 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
551 \docparam{millisecond
}{Number of milliseconds to wait.
}
553 \wxheading{Return value
}
555 Returns TRUE if there is data to be read, FALSE if the timeout was reached.
559 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
},
560 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
561 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
566 \membersection{wxSocketBase::WaitForWrite
}\label{wxsocketbasewaitforwrite
}
568 \func{bool
}{WaitForWrite
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
570 This function waits until you can write to the socket.
572 \wxheading{Parameters
}
574 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
576 \docparam{millisecond
}{Number of milliseconds to wait.
}
578 \wxheading{Return value
}
580 Returns TRUE if you can write to the socket, FALSE if the timeout was reached.
584 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
},
585 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
586 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
591 \membersection{wxSocketBase::WaitForLost
}\label{wxsocketbasewaitforlost
}
593 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
595 This function waits until the connection is lost. This may happen if the
596 peer closes the connection or if the connection breaks.
598 \wxheading{Parameters
}
600 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
602 \docparam{millisecond
}{Number of milliseconds to wait.
}
604 \wxheading{Return value
}
606 Returns TRUE if the connection was lost, FALSE if the timeout was reached.
610 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
611 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
612 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
614 % ---------------------------------------------------------------------------
616 % ---------------------------------------------------------------------------
621 \membersection{wxSocketBase::RestoreState
}\label{wxsocketbaserestorestate
}
623 \func{void
}{RestoreState
}{\void}
625 This function restores the previous state of the socket, as saved
628 Calls to SaveState / RestoreState can be nested.
632 \helpref{wxSocketBase::SaveState
}{wxsocketbasesavestate
}
637 \membersection{wxSocketBase::SaveState
}\label{wxsocketbasesavestate
}
639 \func{void
}{SaveState
}{\void}
641 This function saves the current state of the socket object in a stack:
642 actually it saves all flags (those set with SetFlags, SetNotify, Notify)
643 and the state of the asynchronous callbacks (Callback, CallbackData).
645 Calls to SaveState / RestoreState can be nested.
649 \helpref{wxSocketBase::RestoreState
}{wxsocketbaserestorestate
}
654 \membersection{wxSocketBase::GetLocal
}{wxsocketbasegetlocal
}
656 \constfunc{bool
}{GetLocal
}{\param{wxSockAddress\&
}{addr
\_man}}
658 This function returns the local address field of the socket. The local
659 address field contains the complete local address of the socket (local
660 address, local port, ...).
662 \wxheading{Return value
}
664 It returns TRUE if no errors happened, FALSE otherwise.
669 \membersection{wxSocketBase::GetPeer
}{wxsocketbasegetlocal
}
671 \constfunc{bool
}{GetPeer
}{\param{wxSockAddress\&
}{addr
\_man}}
673 This function returns the peer address field of the socket. The peer
674 address field contains the complete peer host address of the socket
675 (address, port, ...).
677 \wxheading{Return value
}
679 It returns TRUE if no errors happened, FALSE otherwise.
681 % ---------------------------------------------------------------------------
683 % ---------------------------------------------------------------------------
684 \membersection{wxSocketBase::SetEventHandler
}\label{wxsocketbaseseteventhandler
}
686 \func{void
}{SetEventHandler
}{\param{wxEvtHandler\&
}{ evt
\_hdlr},
\param{int
}{ id = -
1}}
688 Sets an event handler to be called when a socket event occurs. The handler
689 will be called for those events for which notification is enabled with
690 SetNotify and Notify.
692 You can also specify a C callback to be called when an event occurs. See
693 Callback and CallbackData.
695 \wxheading{Parameters
}
697 \docparam{evt
\_hdlr}{Specifies the event handler you want to use.
}
699 \docparam{id
}{The id of socket event.
}
703 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
704 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
705 \helpref{wxSocketEvent
}{wxsocketevent
},
706 \helpref{wxEvtHandler
}{wxevthandler
},
707 \helpref{wxSocketBase::Callback
}{wxsocketbasecallback
},
708 \helpref{wxSocketBase::CallbackData
}{wxsocketbasecallbackdata
}
710 \membersection{wxSocketBase::Callback
}\label{wxsocketbasecallback
}
712 \func{wxSocketBase::wxSockCbk
}{Callback
}{\param{wxSocketBase::wxSockCbk
}{ callback
}}
714 You can setup a C callback to be called when an event occurs. The callback
715 will be called only for those events for which notification has been enabled
716 with Notify and SetNotify. The prototype of the callback must be as follows:
719 void SocketCallback(wxSocketBase& sock,wxSocketNotify evt,char *cdata);
722 The first parameter is a reference to the socket object in which the event
723 occured. The second parameter tells you which event occured. (See
\helpref{wxSocket events
}{wxsocketbase
}).
724 The third parameter is the user data you specified using
\helpref{CallbackData
}{wxsocketbasecallbackdata
}.
726 \wxheading{Return value
}
728 A pointer to the previous callback.
732 \helpref{wxSocketBase::CallbackData
}{wxsocketbasecallbackdata
},
733 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
734 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
736 \membersection{wxSocketBase::CallbackData
}\label{wxsocketbasecallbackdata
}
738 \func{char *
}{CallbackData
}{\param{char *
}{cdata
}}
740 This function sets the the user data which will be passed to a
\helpref{C callback
}{wxsocketbasecallback
}.
742 \wxheading{Return value
}
744 A pointer to the previous user data.
746 \helpref{wxSocketBase::Callback
}{wxsocketbasecallback
},
747 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
748 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
750 % ---------------------------------------------------------------------------
751 % CLASS wxSocketClient
752 % ---------------------------------------------------------------------------
753 \section{\class{wxSocketClient
}}\label{wxsocketclient
}
755 \wxheading{Derived from
}
757 \helpref{wxSocketBase
}{wxsocketbase
}
759 \wxheading{Include files
}
763 % ---------------------------------------------------------------------------
765 % ---------------------------------------------------------------------------
769 \membersection{wxSocketClient::wxSocketClient
}
771 \func{}{wxSocketClient
}{\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
773 Constructs a new wxSocketClient.
775 \wxheading{Parameters
}
777 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
782 \membersection{wxSocketClient::
\destruct{wxSocketClient
}}
784 \func{}{\destruct{wxSocketClient
}}{\void}
786 Destroys a wxSocketClient object.
791 \membersection{wxSocketClient::Connect
}\label{wxsocketclientconnect
}
793 \func{bool
}{Connect
}{\param{wxSockAddress\&
}{ address
},
\param{bool
}{ wait = TRUE
}}
795 Connects to a server using the specified address.
797 If
{\it wait
} is TRUE, Connect will wait until the connection completes and
798 the socket is ready to send or receive data, or until an event occurs.
800 {\bf Warning !
} This will block the GUI.
802 If
{\it wait
} is FALSE, Connect will try to establish the connection and
803 return immediately, without blocking the GUI. When used this way, even if
804 Connect returns FALSE, the connection request can be completed later.
805 To detect this, use WaitConnection, or watch "connection" events (for
806 succesful establishment) and "lost" events (for connection failure).
808 \wxheading{Parameters
}
810 \docparam{address
}{Address of the server.
}
812 \docparam{wait
}{If true, waits for the connection to be ready.
}
814 \wxheading{Return value
}
816 Returns TRUE if the connection is established and no error occurs.
818 If
{\it wait
} was TRUE, and Connect returns FALSE, an error occured
819 and the connection failed.
821 If
{\it wait
} was FALSE, and Connect returns FALSE, you should still
822 be prepared to handle the completion of this connection request, either
823 with WaitOnConnect or by watching "connection" and "lost" events.
827 \helpref{wxSocketClient::WaitOnConnect
}{wxsocketclientwaitonconnect
},
828 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
829 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
834 \membersection{wxSocketClient::WaitOnConnect
}\label{wxsocketclientwaitonconnect
}
836 \func{bool
}{WaitOnConnect
}{\param{long
}{ seconds = -
1},
\param{long
}{ milliseconds =
0}}
838 Wait until the connection is succesfully established or until it fails.
839 Use this function after a call to Connect with
{\it wait
} set to FALSE.
841 \wxheading{Parameters
}
843 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
845 \docparam{millisecond
}{Number of milliseconds to wait.
}
847 \wxheading{Return value
}
849 If the connection is succesfully established, it returns TRUE.
851 If the timeout expires, or if the connection fails, it returns FALSE.
855 \helpref{wxSocketClient::Connect
}{wxsocketclientconnect
}
857 % ---------------------------------------------------------------------------
858 % CLASS: wxSocketEvent
859 % ---------------------------------------------------------------------------
860 \section{\class{wxSocketEvent
}}\label{wxsocketevent
}
862 This event class contains information about socket events.
864 \wxheading{Derived from
}
866 \helpref{wxEvent
}{wxevent
}
868 \wxheading{Include files
}
872 \wxheading{Event table macros
}
874 To process a socket event, use these event handler macros to direct input to member
875 functions that take a wxSocketEvent argument.
878 \begin{twocollist
}\itemsep=
0pt
879 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{Process a socket event, supplying the member function.
}
884 \helpref{wxSocketBase
}{wxsocketbase
},
885 \helpref{wxSocketClient
}{wxsocketclient
},
886 \helpref{wxSocketServer
}{wxsocketserver
}
888 \latexignore{\rtfignore{\wxheading{Members
}}}
890 \membersection{wxSocketEvent::wxSocketEvent
}
892 \func{}{wxSocketEvent
}{\param{int
}{ id =
0}}
896 \membersection{wxSocketEvent::SocketEvent
}\label{wxsocketeventsocketevent
}
898 \constfunc{wxSocketNotify
}{SocketEvent
}{\void}
900 Returns the socket event type.
902 % ---------------------------------------------------------------------------
903 % CLASS: wxSocketServer
904 % ---------------------------------------------------------------------------
905 \section{\class{wxSocketServer
}}\label{wxsocketserver
}
907 \wxheading{Derived from
}
909 \helpref{wxSocketBase
}{wxsocketbase
}
911 \wxheading{Include files
}
915 % ---------------------------------------------------------------------------
917 % ---------------------------------------------------------------------------
918 \latexignore{\rtfignore{\wxheading{Members
}}}
923 \membersection{wxSocketServer::wxSocketServer
}\label{wxsocketserverconstr
}
925 \func{}{wxSocketServer
}{\param{wxSockAddress\&
}{ address
},
\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
927 Constructs a new wxSocketServer.
929 \wxheading{Parameters
}
931 \docparam{address
}{Specifies the local address for the server (e.g. port number).
}
933 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
938 \membersection{wxSocketServer::
\destruct{wxSocketServer
}}
940 \func{}{\destruct{wxSocketServer
}}{\void}
942 Destroys a wxSocketServer object (it doesn't close the accepted connections).
947 \membersection{wxSocketServer::Accept
}\label{wxsocketserveraccept
}
949 \func{wxSocketBase *
}{Accept
}{\param{bool
}{ wait = TRUE
}}
951 Creates a new object wxSocketBase and accepts an incoming connection.
953 If
{\it wait
} is TRUE and there are no pending connections to be
954 accepted, it will wait for the next incoming connection to arrive.
955 {\bf Warning !
} This will block the GUI.
957 If
{\it wait
} is FALSE, it will try to accept a pending connection
958 if there is one, but it will always return immediately without
959 blocking the GUI. If you want to use Accept in this way, you can
960 either check for incoming connections with WaitForAccept or watch
961 "connection" events, then call Accept once you know that there is
962 an incoming connection waiting to be accepted.
964 \wxheading{Return value
}
966 Returns an opened socket connection, or NULL if an error occured or
967 if the
{\it wait
} parameter was FALSE and there were no pending
972 \helpref{wxSocketServer::WaitForAccept
}{wxsocketserverwaitforaccept
},
973 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
974 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
975 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}
980 \membersection{wxSocketServer::AcceptWith
}\label{wxsocketserveracceptwith
}
982 \func{bool
}{AcceptWith
}{\param{wxSocketBase\&
}{ socket
},
\param{bool
}{ wait = TRUE
}}
984 Accept an incoming connection using the specified socket object.
985 This is useful when someone wants to inherit wxSocketBase.
987 \wxheading{Parameters
}
989 \docparam{socket
}{Socket to be initialized
}
991 \wxheading{Return value
}
993 Returns TRUE on success, or FALSE if an error occured or if the
994 {\it wait
} parameter was FALSE and there were no pending
997 \helpref{wxSocketServer::WaitForAccept
}{wxsocketserverwaitforaccept
},
998 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
999 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
1000 \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
}