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}}{There is data available for reading.
}
32 \twocolitem{{\bf wxSOCKET
\_OUTPUT}}{The socket is ready to be written to.
}
33 \twocolitem{{\bf wxSOCKET
\_CONNECTION}}{Incoming connection (server), or connection establishment (client).
}
34 \twocolitem{{\bf wxSOCKET
\_LOST}}{The connection has been closed.
}
37 A brief note on how to use these events:
39 The
{\bf wxSOCKET
\_INPUT} event will be issued whenever there is data
40 available for reading. This will be the case if the input queue was
41 empty and new data arrives, or if the application has read some data
42 yet there is still more data available. This means that the application
43 does not need to read all available data in response to a
44 {\bf wxSOCKET
\_INPUT} event, as more events will be produced as
47 The
{\bf wxSOCKET
\_OUTPUT} event is issued when a socket is first
48 connected with Connect or accepted with Accept. After that, new
49 events will be generated only after an output operation fails
50 with
{\bf wxSOCKET
\_WOULDBLOCK} and buffer space becomes available
51 again. This means that the application should assume that it
52 can write data to the socket until an
{\bf wxSOCKET
\_WOULDBLOCK}
53 error occurs; after this, whenever the socket becomes writable
54 again the application will be notified with another
55 {\bf wxSOCKET
\_OUTPUT} event.
57 The
{\bf wxSOCKET
\_CONNECTION} event is issued when a delayed connection
58 request completes succesfully (client) or when a new connection arrives
59 at the incoming queue (server).
61 The
{\bf wxSOCKET
\_LOST} event is issued when a close indication is
62 received for the socket. This means that the connection broke down or
63 that it was closed by the peer. Also, this event will be issued if
64 a delayed connection request fails.
66 % ---------------------------------------------------------------------------
68 % ---------------------------------------------------------------------------
69 \wxheading{Event handling
}
71 To process events from a socket, use the following event handler macro to direct
72 input to member functions that take a
\helpref{wxSocketEvent
}{wxsocketevent
} argument.
75 \begin{twocollist
}\itemsep=
0pt
76 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{A socket event occured.
}
79 % ---------------------------------------------------------------------------
81 % ---------------------------------------------------------------------------
84 \helpref{wxSocketEvent
}{wxsocketevent
},
85 \helpref{wxSocketClient
}{wxsocketclient
},
86 \helpref{wxSocketServer
}{wxsocketserver
}
88 % ---------------------------------------------------------------------------
90 % ---------------------------------------------------------------------------
91 \latexignore{\rtfignore{\wxheading{Members
}}}
93 \membersection{wxSocketBase::wxSocketBase
}
95 \func{}{wxSocketBase
}{\void}
97 Default constructor. Don't use it; use
\helpref{wxSocketClient
}{wxsocketclient
}
98 or
\helpref{wxSocketServer
}{wxsocketserver
}.
100 \membersection{wxSocketBase::
\destruct{wxSocketBase
}}
102 \func{}{\destruct{wxSocketBase
}}{\void}
104 Destroys the wxSocketBase object.
106 % ---------------------------------------------------------------------------
108 % ---------------------------------------------------------------------------
114 \membersection{wxSocketBase::SetFlags
}\label{wxsocketbasesetflags
}
116 \func{void
}{SetFlags
}{\param{wxSocketBase::wxSockFlags
}{ flags
}}
119 \begin{twocollist
}\itemsep=
0pt
120 \twocolitem{{\bf wxSOCKET
\_NONE}}{Normal functionality.
}
121 \twocolitem{{\bf wxSOCKET
\_NOWAIT}}{Read/write as much data as possible and return immediately.
}
122 \twocolitem{{\bf wxSOCKET
\_WAITALL}}{Wait for all required data to be read/written unless an error occurs.
}
123 \twocolitem{{\bf wxSOCKET
\_BLOCK}}{Block the GUI (do not wxYield) while reading/writing data.
}
126 A brief overview on how to use these flags follows.
128 If no flag is specified (this is the same as
{\bf wxSOCKET
\_NONE}),
129 IO calls will return after some data has been read or written, even
130 when the transfer might not be complete. This is the same as issuing
131 exactly one blocking low-level call to recv() or send(). Note that
132 blocking here refers to when the function returns, not to whether
133 the GUI blocks during this time.
135 If
{\bf wxSOCKET
\_NOWAIT} is specified, IO calls will return immediately.
136 Read operations will retrieve only available data. Write operations will
137 write as much data as possible, depending on how much space is available
138 in the output buffer. This is the same as issuing exactly one nonblocking
139 low-level call to recv() or send(). Note that nonblocking here refers to
140 when the function returns, not to whether the GUI blocks during this time.
142 If
{\bf wxSOCKET
\_WAITALL} is specified, IO calls won't return until ALL
143 the data has been read or written (or until an error occurs), blocking if
144 necessary, and issuing several low level calls if necessary. This is the
145 same as having a loop which makes as many blocking low-level calls to
146 recv() or send() as needed so as to transfer all the data. Note that
147 "blocking" here refers to when the function returns, not to whether
148 the GUI blocks during this time.
150 The
{\bf wxSOCKET
\_BLOCK} flag controls whether the GUI blocks during
151 IO operations. If this flag is not used, then the application must take
152 extra care to avoid unwanted reentrance.
156 {\bf wxSOCKET
\_NONE} will try to read at least SOME data, no matter how much.
158 {\bf wxSOCKET
\_NOWAIT} will always return immediately, even if it cannot
159 read or write ANY data.
161 {\bf wxSOCKET
\_WAITALL} will only return when it has read or written ALL
164 {\bf wxSOCKET
\_BLOCK} has nothing to do with the previous flags and
165 it controls whether the GUI blocks.
170 \membersection{wxSocketBase::SetNotify
}\label{wxsocketbasesetnotify
}
172 \func{void
}{SetNotify
}{\param{wxSocketEventFlags
}{ flags
}}
174 SetNotify specifies which socket events are to be sent to the event handler.
175 The
{\it flags
} parameter is a combination of flags ORed toghether. The
176 following flags can be used:
179 \begin{twocollist
}\itemsep=
0pt
180 \twocolitem{{\bf wxSOCKET
\_INPUT\_FLAG}}{to receive wxSOCKET
\_INPUT}
181 \twocolitem{{\bf wxSOCKET
\_OUTPUT\_FLAG}}{to receive wxSOCKET
\_OUTPUT}
182 \twocolitem{{\bf wxSOCKET
\_CONNECTION\_FLAG}}{to receive wxSOCKET
\_CONNECTION}
183 \twocolitem{{\bf wxSOCKET
\_LOST\_FLAG}}{to receive wxSOCKET
\_LOST}
189 sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
192 In this example, the user will be notified about incoming socket data and
193 whenever the connection is closed.
195 For more information on socket events see
\helpref{wxSocket events
}{wxsocketbase
}.
200 \membersection{wxSocketBase::SetTimeout
}\label{wxsocketbasesettimeout
}
202 \func{void
}{SetTimeout
}{\param{int
}{seconds
}}
204 This function sets the default socket timeout in seconds. This
205 timeout applies to IO calls, and also to Wait() functions if you
206 don't specify a wait interval. If you never use SetTimeout(), the
207 default timeout will be
10 minutes.
212 \membersection{wxSocketBase::Notify
}\label{wxsocketbasenotify
}
214 \func{void
}{Notify
}{\param{bool
}{ notify
}}
216 Notify will enable (notify is TRUE) or disable (notify is FALSE) the propagation
223 \membersection{wxSocketBase::Ok
}\label{wxsocketbaseok
}
225 \constfunc{bool
}{Ok
}{\void}
227 Returns TRUE if the socket is initialized and ready and FALSE in other
230 \membersection{wxSocketBase::Error
}\label{wxsocketbaseerror
}
232 \constfunc{bool
}{Error
}{\void}
234 Returns TRUE if an error occured in the last IO operation.
236 The following operations update the Error() status:
237 Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
239 \membersection{wxSocketBase::IsConnected
}\label{wxsocketbaseconnected
}
241 \constfunc{bool
}{IsConnected
}{\void}
243 Returns TRUE if the socket is connected.
245 \membersection{wxSocketBase::IsData
}\label{wxsocketbaseisdata
}
247 \constfunc{bool
}{IsData
}{\void}
249 Returns TRUE if there is data available to be read.
251 \membersection{wxSocketBase::IsDisconnected
}\label{wxsocketbasedisconnected
}
253 \constfunc{bool
}{IsDisconnected
}{\void}
255 Returns TRUE if the socket is disconnected.
257 \membersection{wxSocketBase::IsNoWait
}\label{wxsocketbasenowait
}
259 \constfunc{bool
}{IsNoWait
}{\void}
261 Returns TRUE if the socket mustn't wait.
263 \membersection{wxSocketBase::LastCount
}\label{wxsocketbaselastcount
}
265 \constfunc{wxUint32
}{LastCount
}{\void}
267 Returns the number of bytes read or written by the last IO call.
269 The following operations update the LastCount() value:
270 Read, Write, ReadMsg, WriteMsg, Peek, Unread, Discard.
272 \membersection{wxSocketBase::LastError
}\label{wxsocketbaselasterror
}
274 \constfunc{wxSocketError
}{LastError
}{\void}
276 Returns the last wxSocket error. See
\helpref{wxSocket errors
}{wxsocketbase
}.
278 Please note that this function merely returns the last error code,
279 but it should not be used to determine if an error has occured (this
280 is because successful operations do not change the LastError value).
281 Use Error, instead of LastError, to determine if the last IO call
282 failed. If Error returns TRUE, use LastError to discover the
285 % ---------------------------------------------------------------------------
287 % ---------------------------------------------------------------------------
291 \membersection{wxSocketBase::Peek
}\label{wxsocketbasepeek
}
293 \func{wxSocketBase\&
}{Peek
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
295 This function peeks a buffer of
{\it nbytes
} bytes from the socket.
296 Peeking a buffer doesn't delete it from the socket input queue.
298 Use LastCount to verify the number of bytes actually peeked.
300 Use Error to determine if the operation succeeded.
302 \wxheading{Parameters
}
304 \docparam{buffer
}{Buffer where to put peeked data.
}
306 \docparam{nbytes
}{Number of bytes.
}
308 \wxheading{Return value
}
310 Returns a reference to the current object.
312 \wxheading{Remark/Warning
}
314 The exact behaviour of wxSocketBase::Peek() depends on the combination
315 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
319 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
320 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
321 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
322 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
327 \membersection{wxSocketBase::Read
}\label{wxsocketbaseread
}
329 \func{wxSocketBase\&
}{Read
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
331 This function reads a buffer of
{\it nbytes
} bytes from the socket.
333 Use LastCount to verify the number of bytes actually read.
335 Use Error to determine if the operation succeeded.
337 \wxheading{Parameters
}
339 \docparam{buffer
}{Buffer where to put read data.
}
341 \docparam{nbytes
}{Number of bytes.
}
343 \wxheading{Return value
}
345 Returns a reference to the current object.
347 \wxheading{Remark/Warning
}
349 The exact behaviour of wxSocketBase::Read() depends on the combination
350 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
354 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
355 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
356 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
357 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
362 \membersection{wxSocketBase::Write
}\label{wxsocketbasewrite
}
364 \func{wxSocketBase\&
}{Write
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
366 This function writes a buffer of
{\it nbytes
} bytes to the socket.
368 Use LastCount to verify the number of bytes actually written.
370 Use Error to determine if the operation succeeded.
372 \wxheading{Parameters
}
374 \docparam{buffer
}{Buffer with the data to be sent.
}
376 \docparam{nbytes
}{Number of bytes.
}
378 \wxheading{Return value
}
380 Returns a reference to the current object.
382 \wxheading{Remark/Warning
}
384 The exact behaviour of wxSocketBase::Write() depends on the combination
385 of flags being used. For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
389 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
390 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
391 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
392 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}
397 \membersection{wxSocketBase::WriteMsg
}\label{wxsocketbasewritemsg
}
399 \func{wxSocketBase\&
}{WriteMsg
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
401 This function writes a buffer of
{\it nbytes
} bytes from the socket, but it
402 writes a short header before so that ReadMsg knows how much data should it
403 actually read. So, a buffer sent with WriteMsg
{\bf must
} be read with
404 ReadMsg. This function always waits for the entire buffer to be sent,
405 unless an error occurs.
407 Use LastCount to verify the number of bytes actually written.
409 Use Error to determine if the operation succeeded.
411 \wxheading{Parameters
}
413 \docparam{buffer
}{Buffer with the data to be sent.
}
415 \docparam{nbytes
}{Number of bytes.
}
417 \wxheading{Return value
}
419 Returns a reference to the current object.
421 \wxheading{Remark/Warning
}
423 wxSocketBase::WriteMsg() will behave as if the
{\bf wxSOCKET
\_WAITALL} flag
424 was always set and it will always ignore the
{\bf wxSOCKET
\_NOWAIT} flag.
425 The exact behaviour of WriteMsg depends on the
{\bf wxSOCKET
\_BLOCK} flag.
426 For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
430 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
431 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
432 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
433 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
},
434 \helpref{wxSocketBase::ReadMsg
}{wxsocketbasereadmsg
}
439 \membersection{wxSocketBase::ReadMsg
}\label{wxsocketbasereadmsg
}
441 \func{wxSocketBase\&
}{ReadMsg
}{\param{char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
443 This function reads a buffer sent by WriteMsg on a socket. If the buffer passed
444 to the function isn't big enough, the remaining bytes will be discarded. This
445 function always waits for the buffer to be entirely filled, unless an error occurs.
447 Use LastCount to verify the number of bytes actually read.
449 Use Error to determine if the operation succeeded.
451 \wxheading{Parameters
}
453 \docparam{buffer
}{Buffer where to put read data.
}
455 \docparam{nbytes
}{Number of bytes allocated for the buffer.
}
457 \wxheading{Return value
}
459 Returns a reference to the current object.
461 \wxheading{Remark/Warning
}
463 wxSocketBase::ReadMsg() will behave as if the
{\bf wxSOCKET
\_WAITALL} flag
464 was always set and it will always ignore the
{\bf wxSOCKET
\_NOWAIT} flag.
465 The exact behaviour of ReadMsg depends on the
{\bf wxSOCKET
\_BLOCK} flag.
466 For a detailed explanation, see
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
}.
470 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
471 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
},
472 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
473 \helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
},
474 \helpref{wxSocketBase::WriteMsg
}{wxsocketbasewritemsg
}
479 \membersection{wxSocketBase::Unread
}\label{wxsocketbaseunread
}
481 \func{wxSocketBase\&
}{Unread
}{\param{const char *
}{ buffer
},
\param{wxUint32
}{ nbytes
}}
483 This function unreads a buffer. That is, the data in the buffer is put back
484 in the incoming queue. This function is not affected by wxSocket flags.
486 If you use LastCount, it will always return
{\it nbytes
}.
488 If you use Error, it will always return FALSE.
490 \wxheading{Parameters
}
492 \docparam{buffer
}{Buffer to be unread.
}
494 \docparam{nbytes
}{Number of bytes.
}
496 \wxheading{Return value
}
498 Returns a reference to the current object.
502 \helpref{wxSocketBase::Error
}{wxsocketbaseerror
},
503 \helpref{wxSocketBase::LastCount
}{wxsocketbaselastcount
},
504 \helpref{wxSocketBase::LastError
}{wxsocketbaselasterror
}
509 \membersection{wxSocketBase::Discard
}\label{wxsocketbasediscard
}
511 \func{wxSocketBase\&
}{Discard
}{\void}
513 This function simply deletes all bytes in the incoming queue. This function
514 always returns immediately and its operation is not affected by IO flags.
516 Use LastCount to see the number of bytes discarded.
518 If you use Error, it will always return FALSE.
520 % ---------------------------------------------------------------------------
522 % ---------------------------------------------------------------------------
523 \membersection{wxSocketBase::Wait
}\label{wxsocketbasewait
}
525 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
527 This function waits until one of the following conditions is true: there
528 is data available for reading; the output buffer is empty (you can send
529 new data); the connection has been lost; an incoming connection arrived
530 (only for servers); a connection request has completed (only for clients).
531 It is usually better to use the individual Wait functions to wait for the
534 \wxheading{Parameters
}
536 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
538 \docparam{millisecond
}{Number of milliseconds to wait.
}
540 \wxheading{Return value
}
542 Returns TRUE if an event occured, FALSE if the timeout was reached.
546 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
547 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
548 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
553 \membersection{wxSocketBase::WaitForRead
}\label{wxsocketbasewaitforread
}
555 \func{bool
}{WaitForRead
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
557 This function waits until there is data available to be read.
559 \wxheading{Parameters
}
561 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
563 \docparam{millisecond
}{Number of milliseconds to wait.
}
565 \wxheading{Return value
}
567 Returns TRUE if there is data to be read, FALSE if the timeout was reached.
571 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
},
572 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
573 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
578 \membersection{wxSocketBase::WaitForWrite
}\label{wxsocketbasewaitforwrite
}
580 \func{bool
}{WaitForWrite
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
582 This function waits until you can write to the socket.
584 \wxheading{Parameters
}
586 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
588 \docparam{millisecond
}{Number of milliseconds to wait.
}
590 \wxheading{Return value
}
592 Returns TRUE if you can write to the socket, FALSE if the timeout was reached.
596 \helpref{wxSocketBase::Wait
}{wxsocketbasewait
},
597 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
598 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
603 \membersection{wxSocketBase::WaitForLost
}\label{wxsocketbasewaitforlost
}
605 \func{bool
}{Wait
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
607 This function waits until the connection is lost. This may happen if the
608 peer closes the connection or if the connection breaks.
610 \wxheading{Parameters
}
612 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
614 \docparam{millisecond
}{Number of milliseconds to wait.
}
616 \wxheading{Return value
}
618 Returns TRUE if the connection was lost, FALSE if the timeout was reached.
622 \helpref{wxSocketBase::WaitForRead
}{wxsocketbasewaitforread
},
623 \helpref{wxSocketBase::WaitForWrite
}{wxsocketbasewaitforwrite
},
624 \helpref{wxSocketBase::WaitForLost
}{wxsocketbasewaitforlost
}
626 % ---------------------------------------------------------------------------
628 % ---------------------------------------------------------------------------
633 \membersection{wxSocketBase::RestoreState
}\label{wxsocketbaserestorestate
}
635 \func{void
}{RestoreState
}{\void}
637 This function restores the previous state of the socket, as saved
640 Calls to SaveState / RestoreState can be nested.
644 \helpref{wxSocketBase::SaveState
}{wxsocketbasesavestate
}
649 \membersection{wxSocketBase::SaveState
}\label{wxsocketbasesavestate
}
651 \func{void
}{SaveState
}{\void}
653 This function saves the current state of the socket object in a stack:
654 actually it saves all flags (those set with SetFlags, SetNotify, Notify)
655 and the state of the asynchronous callbacks (Callback, CallbackData).
657 Calls to SaveState / RestoreState can be nested.
661 \helpref{wxSocketBase::RestoreState
}{wxsocketbaserestorestate
}
666 \membersection{wxSocketBase::GetLocal
}{wxsocketbasegetlocal
}
668 \constfunc{bool
}{GetLocal
}{\param{wxSockAddress\&
}{addr
\_man}}
670 This function returns the local address field of the socket. The local
671 address field contains the complete local address of the socket (local
672 address, local port, ...).
674 \wxheading{Return value
}
676 It returns TRUE if no errors happened, FALSE otherwise.
681 \membersection{wxSocketBase::GetPeer
}{wxsocketbasegetlocal
}
683 \constfunc{bool
}{GetPeer
}{\param{wxSockAddress\&
}{addr
\_man}}
685 This function returns the peer address field of the socket. The peer
686 address field contains the complete peer host address of the socket
687 (address, port, ...).
689 \wxheading{Return value
}
691 It returns TRUE if no errors happened, FALSE otherwise.
693 % ---------------------------------------------------------------------------
695 % ---------------------------------------------------------------------------
696 \membersection{wxSocketBase::SetEventHandler
}\label{wxsocketbaseseteventhandler
}
698 \func{void
}{SetEventHandler
}{\param{wxEvtHandler\&
}{ evt
\_hdlr},
\param{int
}{ id = -
1}}
700 Sets an event handler to be called when a socket event occurs. The handler
701 will be called for those events for which notification is enabled with
702 SetNotify and Notify.
704 You can also specify a callback function to be called when an event occurs.
705 See
\helpref{Callback
}{wxsocketbasecallback
} and
\helpref{CallbackData
}{wxsocketbasecallbackdata
}.
707 \wxheading{Parameters
}
709 \docparam{evt
\_hdlr}{Specifies the event handler you want to use.
}
711 \docparam{id
}{The id of socket event.
}
715 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
716 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
717 \helpref{wxSocketEvent
}{wxsocketevent
},
718 \helpref{wxEvtHandler
}{wxevthandler
},
719 \helpref{wxSocketBase::Callback
}{wxsocketbasecallback
},
720 \helpref{wxSocketBase::CallbackData
}{wxsocketbasecallbackdata
}
722 \membersection{wxSocketBase::Callback
}\label{wxsocketbasecallback
}
724 \func{wxSocketBase::wxSockCbk
}{Callback
}{\param{wxSocketBase::wxSockCbk
}{ callback
}}
726 You can setup a callback function to be called when an event occurs. The function
727 will be called only for those events for which notification has been enabled
728 with Notify and SetNotify. The prototype of the callback must be as follows:
731 void SocketCallback(wxSocketBase& sock, wxSocketNotify evt, char *cdata);
734 The first parameter is a reference to the socket object in which the event
735 occured. The second parameter tells you which event occured. (See
\helpref{wxSocket events
}{wxsocketbase
}).
736 The third parameter is the user data you specified using
\helpref{CallbackData
}{wxsocketbasecallbackdata
}.
738 \wxheading{Return value
}
740 A pointer to the previous callback.
744 \helpref{wxSocketBase::CallbackData
}{wxsocketbasecallbackdata
},
745 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
746 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
748 \membersection{wxSocketBase::CallbackData
}\label{wxsocketbasecallbackdata
}
750 \func{char *
}{CallbackData
}{\param{char *
}{cdata
}}
752 This function sets the the user data which will be passed to a
753 callback function set via
\helpref{Callback
}{wxsocketbasecallback
}.
755 \wxheading{Return value
}
757 A pointer to the previous user data.
759 \helpref{wxSocketBase::Callback
}{wxsocketbasecallback
},
760 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
761 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
763 % ---------------------------------------------------------------------------
764 % CLASS wxSocketClient
765 % ---------------------------------------------------------------------------
766 \section{\class{wxSocketClient
}}\label{wxsocketclient
}
768 \wxheading{Derived from
}
770 \helpref{wxSocketBase
}{wxsocketbase
}
772 \wxheading{Include files
}
776 % ---------------------------------------------------------------------------
778 % ---------------------------------------------------------------------------
782 \membersection{wxSocketClient::wxSocketClient
}
784 \func{}{wxSocketClient
}{\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
786 Constructs a new wxSocketClient.
788 \wxheading{Parameters
}
790 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
795 \membersection{wxSocketClient::
\destruct{wxSocketClient
}}
797 \func{}{\destruct{wxSocketClient
}}{\void}
799 Destroys a wxSocketClient object.
804 \membersection{wxSocketClient::Connect
}\label{wxsocketclientconnect
}
806 \func{bool
}{Connect
}{\param{wxSockAddress\&
}{ address
},
\param{bool
}{ wait = TRUE
}}
808 Connects to a server using the specified address.
810 If
{\it wait
} is TRUE, Connect will wait until the connection completes
811 successfully, or until an event occurs.
{\bf Warning !
} This will block the GUI.
813 If
{\it wait
} is FALSE, Connect will try to establish the connection and
814 return immediately, without blocking the GUI. When used this way, even if
815 Connect returns FALSE, the connection request can be completed later.
816 To detect this, use WaitConnection, or catch
{\bf wxSOCKET
\_CONNECTION}
817 events (for successful establishment) and
{\bf wxSOCKET
\_LOST} events
818 (for connection failure).
820 \wxheading{Parameters
}
822 \docparam{address
}{Address of the server.
}
824 \docparam{wait
}{If TRUE, waits for the connection to be ready.
}
826 \wxheading{Return value
}
828 Returns TRUE if the connection is established and no error occurs.
830 If
{\it wait
} was TRUE, and Connect returns FALSE, an error occured
831 and the connection failed.
833 If
{\it wait
} was FALSE, and Connect returns FALSE, you should still
834 be prepared to handle the completion of this connection request, either
835 with WaitOnConnect or by watching
{\bf wxSOCKET
\_CONNECTION} and
836 {\bf wxSOCKET
\_LOST} events.
840 \helpref{wxSocketClient::WaitOnConnect
}{wxsocketclientwaitonconnect
},
841 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
842 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
}
847 \membersection{wxSocketClient::WaitOnConnect
}\label{wxsocketclientwaitonconnect
}
849 \func{bool
}{WaitOnConnect
}{\param{long
}{ seconds = -
1},
\param{long
}{ milliseconds =
0}}
851 Wait until the connection is succesfully established or until it fails.
852 Use this function after a call to Connect with
{\it wait
} set to FALSE.
854 \wxheading{Parameters
}
856 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
858 \docparam{millisecond
}{Number of milliseconds to wait.
}
860 \wxheading{Return value
}
862 If the connection is succesfully established, it returns TRUE.
864 If the timeout expires, or if the connection fails, it returns FALSE.
868 \helpref{wxSocketClient::Connect
}{wxsocketclientconnect
}
870 % ---------------------------------------------------------------------------
871 % CLASS: wxSocketEvent
872 % ---------------------------------------------------------------------------
873 \section{\class{wxSocketEvent
}}\label{wxsocketevent
}
875 This event class contains information about socket events.
877 \wxheading{Derived from
}
879 \helpref{wxEvent
}{wxevent
}
881 \wxheading{Include files
}
885 \wxheading{Event table macros
}
887 To process a socket event, use these event handler macros to direct input to member
888 functions that take a wxSocketEvent argument.
891 \begin{twocollist
}\itemsep=
0pt
892 \twocolitem{{\bf EVT
\_SOCKET(id, func)
}}{Process a socket event, supplying the member function.
}
897 \helpref{wxSocketBase
}{wxsocketbase
},
898 \helpref{wxSocketClient
}{wxsocketclient
},
899 \helpref{wxSocketServer
}{wxsocketserver
}
901 \latexignore{\rtfignore{\wxheading{Members
}}}
903 \membersection{wxSocketEvent::wxSocketEvent
}
905 \func{}{wxSocketEvent
}{\param{int
}{ id =
0}}
909 \membersection{wxSocketEvent::SocketEvent
}\label{wxsocketeventsocketevent
}
911 \constfunc{wxSocketNotify
}{SocketEvent
}{\void}
913 Returns the socket event type.
915 % ---------------------------------------------------------------------------
916 % CLASS: wxSocketServer
917 % ---------------------------------------------------------------------------
918 \section{\class{wxSocketServer
}}\label{wxsocketserver
}
920 \wxheading{Derived from
}
922 \helpref{wxSocketBase
}{wxsocketbase
}
924 \wxheading{Include files
}
928 % ---------------------------------------------------------------------------
930 % ---------------------------------------------------------------------------
931 \latexignore{\rtfignore{\wxheading{Members
}}}
936 \membersection{wxSocketServer::wxSocketServer
}\label{wxsocketserverconstr
}
938 \func{}{wxSocketServer
}{\param{wxSockAddress\&
}{ address
},
\param{wxSockFlags
}{ flags = wxSocketBase::NONE
}}
940 Constructs a new wxSocketServer.
942 \wxheading{Parameters
}
944 \docparam{address
}{Specifies the local address for the server (e.g. port number).
}
946 \docparam{flags
}{Socket flags (See
\helpref{wxSocketBase::SetFlags
}{wxsocketbasesetflags
})
}
951 \membersection{wxSocketServer::
\destruct{wxSocketServer
}}
953 \func{}{\destruct{wxSocketServer
}}{\void}
955 Destroys a wxSocketServer object (it doesn't close the accepted connections).
960 \membersection{wxSocketServer::Accept
}\label{wxsocketserveraccept
}
962 \func{wxSocketBase *
}{Accept
}{\param{bool
}{ wait = TRUE
}}
964 Creates a new object wxSocketBase and accepts an incoming connection.
966 If
{\it wait
} is TRUE and there are no pending connections to be
967 accepted, it will wait for the next incoming connection to arrive.
968 {\bf Warning !
} This will block the GUI.
970 If
{\it wait
} is FALSE, it will try to accept a pending connection
971 if there is one, but it will always return immediately without
972 blocking the GUI. If you want to use Accept in this way, you can
973 either check for incoming connections with WaitForAccept or watch
974 {\bf wxSOCKET
\_CONNECTION} events, then call Accept once you know
975 that there is an incoming connection waiting to be accepted.
977 \wxheading{Return value
}
979 Returns an opened socket connection, or NULL if an error occured or
980 if the
{\it wait
} parameter was FALSE and there were no pending
985 \helpref{wxSocketServer::WaitForAccept
}{wxsocketserverwaitforaccept
},
986 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
987 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
988 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}
993 \membersection{wxSocketServer::AcceptWith
}\label{wxsocketserveracceptwith
}
995 \func{bool
}{AcceptWith
}{\param{wxSocketBase\&
}{ socket
},
\param{bool
}{ wait = TRUE
}}
997 Accept an incoming connection using the specified socket object.
999 \wxheading{Parameters
}
1001 \docparam{socket
}{Socket to be initialized
}
1003 \wxheading{Return value
}
1005 Returns TRUE on success, or FALSE if an error occured or if the
1006 {\it wait
} parameter was FALSE and there were no pending
1009 \helpref{wxSocketServer::WaitForAccept
}{wxsocketserverwaitforaccept
},
1010 \helpref{wxSocketBase::SetNotify
}{wxsocketbasesetnotify
},
1011 \helpref{wxSocketBase::Notify
}{wxsocketbasenotify
},
1012 \helpref{wxSocketServer::Accept
}{wxsocketserveraccept
} for a detailed explanation
1017 \membersection{wxSocketServer::WaitForAccept
}\label{wxsocketserverwaitforaccept
}
1019 \func{bool
}{WaitForAccept
}{\param{long
}{ seconds = -
1},
\param{long
}{ millisecond =
0}}
1021 This function waits for an incoming connection. Use it if you want to call
1022 Accept or AcceptWith with
{\it wait
} set to FALSE, to detect when an incoming
1023 connection is waiting to be accepted.
1025 \wxheading{Parameters
}
1027 \docparam{seconds
}{Number of seconds to wait. If -
1, it will wait for the default timeout set with SetTimeout.
}
1029 \docparam{millisecond
}{Number of milliseconds to wait.
}
1031 \wxheading{Return value
}
1033 Returns TRUE if an incoming connection arrived, FALSE if the timeout expired.
1035 \wxheading{See also
}
1037 \helpref{wxSocketServer::Accept
}{wxsocketserveraccept
},
1038 \helpref{wxSocketServer::AcceptWith
}{wxsocketserveracceptwith
}