7e9a386e10
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3569 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
811 lines
23 KiB
TeX
811 lines
23 KiB
TeX
\section{\class{wxSocketBase}}\label{wxsocketbase}
|
|
|
|
\wxheading{Derived from}
|
|
|
|
\helpref{wxEvtHandler}{wxevthandler}
|
|
|
|
\wxheading{Include files}
|
|
|
|
<wx/socket.h>
|
|
|
|
\wxheading{wxSocket errors}%\label{wxsocketerrs} % Labels don't work on a non-section!
|
|
|
|
\twocolwidtha{7cm}
|
|
\begin{twocollist}\itemsep=0pt
|
|
\twocolitem{{\bf wxSOCKET\_NOERROR}}{No error happened.}
|
|
\twocolitem{{\bf wxSOCKET\_INVOP}}{Invalid operation.}
|
|
\twocolitem{{\bf wxSOCKET\_IOERR}}{Input/Output error.}
|
|
\twocolitem{{\bf wxSOCKET\_INVADDR}}{Invalid address passed to wxSocket.}
|
|
\twocolitem{{\bf wxSOCKET\_INVSOCK}}{Invalid socket (uninitialized).}
|
|
\twocolitem{{\bf wxSOCKET\_NOHOST}}{No corresponding host.}
|
|
\twocolitem{{\bf wxSOCKET\_INVPORT}}{Invalid port.}
|
|
\twocolitem{{\bf wxSOCKET\_TRYAGAIN}}{The IO call has a timeout or is in non-blocking mode.}
|
|
\twocolitem{{\bf wxSOCKET\_MEMERR}}{Memory exhausted.}
|
|
\end{twocollist}%
|
|
|
|
\wxheading{wxSocket events}
|
|
|
|
\twocolwidtha{7cm}
|
|
\begin{twocollist}\itemsep=0pt
|
|
\twocolitem{{\bf wxSOCKET\_INPUT}}{Some data are ready to be got.}
|
|
\twocolitem{{\bf wxSOCKET\_OUTPUT}}{The socket is ready to be written to.}
|
|
\twocolitem{{\bf wxSOCKET\_CONNECTION}}{Someone want to connect our server.}
|
|
\twocolitem{{\bf wxSOCKET\_LOST}}{The connection has been broken.}
|
|
\twocolitem{{\bf wxSOCKET\_MAX\_EVENT}}{This should never happen but the compiler may complain about it.}
|
|
\end{twocollist}%
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% Event handling
|
|
% ---------------------------------------------------------------------------
|
|
\wxheading{Event handling}
|
|
|
|
To process events from a socket, use the following event handler macro to direct
|
|
input to member
|
|
functions that take a \helpref{wxSocketEvent}{wxsocketevent} argument.
|
|
|
|
\twocolwidtha{7cm}%
|
|
\begin{twocollist}\itemsep=0pt
|
|
\twocolitem{{\bf EVT\_SOCKET(id, func)}}{A socket event occured.}
|
|
\end{twocollist}%
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% See also ...
|
|
% ---------------------------------------------------------------------------
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketEvent}{wxsocketevent}\\
|
|
\helpref{wxSocketClient}{wxsocketclient}\\
|
|
\helpref{wxSocketServer}{wxsocketserver}
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% Members
|
|
% ---------------------------------------------------------------------------
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
\membersection{wxSocketBase::wxSocketBase}
|
|
|
|
\func{}{wxSocketBase}{\void}
|
|
|
|
Default constructor but don't use it, you must use \helpref{wxSocketClient}{wxsocketclient}
|
|
or \helpref{wxSocketServer}{wxsocketserver}.
|
|
|
|
\membersection{wxSocketBase::\destruct{wxSocketBase}}
|
|
|
|
\func{}{\destruct{wxSocketBase}}{\void}
|
|
|
|
Destroys the wxSocketBase object.
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% State functions
|
|
% ---------------------------------------------------------------------------
|
|
|
|
%
|
|
% SetFlags
|
|
%
|
|
|
|
\membersection{wxSocketBase::SetFlags}\label{wxsocketbasesetflags}
|
|
|
|
\func{void}{SetFlags}{\param{wxSocketBase::wxSockFlags}{ flags}}
|
|
|
|
\twocolwidtha{7cm}
|
|
\begin{twocollist}\itemsep=0pt
|
|
\twocolitem{{\bf wxSocketBase::NONE}}{Normal functionnalities.}
|
|
\twocolitem{{\bf wxSocketBase::NOWAIT}}{Get the available data in the input queue and exit immediately.}
|
|
\twocolitem{{\bf wxSocketBase::WAITALL}}{Wait for all required data unless an error occured.}
|
|
\twocolitem{{\bf wxSocketBase::SPEED}}{Disable the asynchronous IO functionnality.}
|
|
\end{twocollist}
|
|
|
|
%
|
|
% SetNotify
|
|
%
|
|
\membersection{wxSocketBase::SetNotify}\label{wxsocketbasesetnotify}
|
|
|
|
\func{void}{SetNotify}{\param{wxSocketEventFlags}{ event_flags}}
|
|
|
|
SetNotify setups which socket events are to be sent to the event handler.
|
|
You specify in parameters a mask of wxSocket events. The flags is:
|
|
|
|
\twocolwidtha{7cm}
|
|
\begin{twocollist}\itemsep=0pt
|
|
\twocolitem{{\bf wxSOCKET\_INPUT\_FLAG}}{to receive wxSOCKET_INPUT}
|
|
\twocolitem{{\bf wxSOCKET\_OUTPUT\_FLAG}}{to receive wxSOCKET_OUTPUT}
|
|
\twocolitem{{\bf wxSOCKET\_CONNECTION\_FLAG}}{to receive wxSOCKET_CONNECTION}
|
|
\twocolitem{{\bf wxSOCKET\_LOST\_FLAG}}{to receive wxSOCKET_LOST}
|
|
\end{twocollist}%
|
|
|
|
For example:
|
|
\begin{verbatim}
|
|
sock.SetNotify(wxSOCKET\_INPUT\_FLAG | wxSOCKET\_LOST\_FLAG);
|
|
\end{verbatim}
|
|
In this example, the user will be notified about incoming socket datas and
|
|
a broken connection.
|
|
|
|
For more information on socket events see \helpref{wxSocket events}{wxsocketbase}.
|
|
|
|
%
|
|
% SetTimeout
|
|
%
|
|
\membersection{wxSocketBase::SetTimeout}{wxsocketbasesettimeout}
|
|
|
|
\func{void}{SetTimeout}{\param{int }{seconds}}
|
|
|
|
This function sets the socket timeout in seconds.
|
|
|
|
%
|
|
% Notify
|
|
%
|
|
\membersection{wxSocketBase::Notify}\label{wxsocketbasenotify}
|
|
|
|
\func{void}{Notify}{\param{bool}{ notify}}
|
|
|
|
Notify will enable (notify is TRUE) or disable (notify is FALSE) the propagation
|
|
of socket events.
|
|
|
|
%
|
|
% Ok
|
|
%
|
|
|
|
\membersection{wxSocketBase::Ok}\label{wxsocketbaseok}
|
|
|
|
\constfunc{bool}{Ok}{\void}
|
|
|
|
Returns TRUE if the socket is initialized and ready and FALSE in other
|
|
cases.
|
|
|
|
\membersection{wxSocketBase::Error}\label{wxsocketbaseerror}
|
|
|
|
\constfunc{bool}{Error}{\void}
|
|
|
|
Returns TRUE if an error occured.
|
|
|
|
\membersection{wxSocketBase::IsConnected}\label{wxsocketbaseconnected}
|
|
|
|
\constfunc{bool}{IsConnected}{\void}
|
|
|
|
Returns TRUE if the socket is connected.
|
|
|
|
\membersection{wxSocketBase::IsData}\label{wxsocketbaseisdata}
|
|
|
|
\constfunc{bool}{IsData}{\void}
|
|
|
|
Returns TRUE if some data is arrived on the socket.
|
|
|
|
\membersection{wxSocketBase::IsDisconnected}\label{wxsocketbasedisconnected}
|
|
|
|
\constfunc{bool}{IsDisconnected}{\void}
|
|
|
|
Returns TRUE if the socket is disconnected.
|
|
|
|
\membersection{wxSocketBase::IsNoWait}\label{wxsocketbasenowait}
|
|
|
|
\constfunc{bool}{IsNoWait}{\void}
|
|
|
|
Returns TRUE if the socket mustn't wait.
|
|
|
|
\membersection{wxSocketBase::LastCount}\label{wxsocketbaselastcount}
|
|
|
|
\constfunc{wxUint32}{LastCount}{\void}
|
|
|
|
Returns the number of bytes read or written by the last IO call.
|
|
|
|
\membersection{wxSocketBase::LastError}\label{wxsocketbaselasterror}
|
|
|
|
\constfunc{wxSocketError}{LastError}{\void}
|
|
|
|
Returns the last occured wxSocket error. See \helpref{wxSocket errors}{wxsocketbase}.
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% IO calls
|
|
% ---------------------------------------------------------------------------
|
|
%
|
|
% Peek
|
|
%
|
|
\membersection{wxSocketBase::Peek}\label{wxsocketbasepeek}
|
|
|
|
\func{wxSocketBase\&}{Peek}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
|
|
|
|
This function peeks a buffer of {\it nbytes} bytes from the socket. Peeking a buffer
|
|
doesn't delete it from the system socket in-queue.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{buffer}{Buffer where to put peeked data.}
|
|
|
|
\docparam{nbytes}{Number of bytes.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns a reference to the current object.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
|
|
\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
|
|
\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
|
|
|
|
%
|
|
% Read
|
|
%
|
|
\membersection{wxSocketBase::Read}\label{wxsocketbaseread}
|
|
|
|
\func{wxSocketBase\&}{Read}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
|
|
|
|
This function reads a buffer of {\it nbytes} bytes from the socket.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{buffer}{Buffer where to put read data.}
|
|
|
|
\docparam{nbytes}{Number of bytes.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns a reference to the current object.
|
|
|
|
\wxheading{Remark/Warning}
|
|
|
|
By default, Read uses an internal asynchronous manager: it will send data when
|
|
the socket requests them. It is particularly interesting when you enter a long
|
|
data transfer (e.g. a big file, an image, ...). But it is also buggy when you
|
|
simply discuss with the peer using user data. In this case, wxSocket prepares
|
|
itself to send data (Write wait for them to be sent) and during a GUI refresh
|
|
the user enters new data, which involves a new Read call though the previous
|
|
isn't finished. Well, in most cases it can work but it might fail too.
|
|
So I advise you to use the SPEED flag, which disables the asynchronous manager,
|
|
when you just want to discuss with the peer.
|
|
|
|
This remark is also valid for all IO call.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::Error}{wxsocketbaseerror},
|
|
\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount},
|
|
\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
|
|
|
|
%
|
|
% Write
|
|
%
|
|
\membersection{wxSocketBase::Write}\label{wxsocketbasewrite}
|
|
|
|
\func{wxSocketBase\&}{Write}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
|
|
|
|
This function writes a buffer of {\it nbytes} bytes from the socket.
|
|
|
|
\wxheading{Remark/Warning}
|
|
|
|
By default, Write uses an internal asynchronous manager: it will send data when
|
|
the socket requests them. It is particularly interesting when you enter a long
|
|
data transfer (e.g. a big file, an image, ...). But it is also buggy when you
|
|
simply discuss with the peer using user data. In this case, wxSocket prepares
|
|
itself to send data (Write wait for them to be sent) and during a GUI refresh
|
|
the user enters new data, which involves a new Write call though the previous
|
|
isn't finished. Well, in most cases it can work but it might fail too.
|
|
So I advise you to use the SPEED flag, which disables the asynchronous manager,
|
|
when you just want to discuss with the peer.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{buffer}{Buffer where to get the data to write.}
|
|
|
|
\docparam{nbytes}{Number of bytes.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns a reference to the current object.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
|
|
\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
|
|
\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
|
|
|
|
%
|
|
% WriteMsg
|
|
%
|
|
\membersection{wxSocketBase::WriteMsg}\label{wxsocketbasewritemsg}
|
|
|
|
\func{wxSocketBase\&}{WriteMsg}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
|
|
|
|
This function writes a buffer of {\it nbytes} bytes from the socket. But it
|
|
writes a short header before so that ReadMsg can alloc the right size for
|
|
the buffer. So a buffer sent with WriteMsg {\bf must} be read with ReadMsg.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{buffer}{Buffer where to put data peeked.}
|
|
|
|
\docparam{nbytes}{Number of bytes.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns a reference to the current object.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
|
|
\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
|
|
\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}\\
|
|
\helpref{wxSocketBase::ReadMsg}{wxsocketbasereadmsg}
|
|
|
|
%
|
|
% ReadMsg
|
|
%
|
|
\membersection{wxSocketBase::ReadMsg}\label{wxsocketbasereadmsg}
|
|
|
|
\func{wxSocketBase\&}{ReadMsg}{\param{char *}{ buffer}, \param{wxUint32}{ nbytes}}
|
|
|
|
This function reads a buffer sent by WriteMsg on a socket. If the buffer passed
|
|
to the function isn't big enough, the function filled it and then discard the
|
|
bytes left. This function always wait for the buffer to be entirely filled.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{buffer}{Buffer where to put read data.}
|
|
|
|
\docparam{nbytes}{Number of bytes allocated for the buffer.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns a reference to the current object.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
|
|
\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
|
|
\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}\\
|
|
\helpref{wxSocketBase::WriteMsg}{wxsocketbasewritemsg}
|
|
|
|
%
|
|
% Unread
|
|
%
|
|
\membersection{wxSocketBase::Unread}\label{wxsocketbaseunread}
|
|
|
|
\func{wxSocketBase\&}{Unread}{\param{const char *}{ buffer}, \param{wxUint32}{ nbytes}}
|
|
|
|
This function unreads a buffer. It means that the buffer is put in the top
|
|
of the incoming queue. But, it is put also at the end of all unread buffers.
|
|
It is useful for sockets because we can't seek it.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{buffer}{Buffer to be unread.}
|
|
|
|
\docparam{nbytes}{Number of bytes.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns a reference to the current object.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::Error}{wxsocketbaseerror}\\
|
|
\helpref{wxSocketBase::LastCount}{wxsocketbaselastcount}\\
|
|
\helpref{wxSocketBase::LastError}{wxsocketbaselasterror}
|
|
|
|
%
|
|
% Discard
|
|
%
|
|
\membersection{wxSocketBase::Discard}\label{wxsocketbasediscard}
|
|
|
|
\func{wxSocketBase\&}{Discard}{\void}
|
|
|
|
This function simply deletes all bytes in the incoming queue. This function
|
|
doesn't wait.
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% Wait functions
|
|
% ---------------------------------------------------------------------------
|
|
\membersection{wxSocketBase::Wait}\label{wxsocketbasewait}
|
|
|
|
\func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
|
|
|
|
This function waits for an event: it could be an incoming byte, the possibility
|
|
for the client to write, a lost connection, an incoming connection, an
|
|
established connection.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{seconds}{Number of seconds to wait. By default, it waits infinitely.}
|
|
|
|
\docparam{millisecond}{Number of milliseconds to wait.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns TRUE if an event occured, FALSE if the timeout was reached.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}\\
|
|
\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}\\
|
|
\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
|
|
|
|
%
|
|
% WaitForRead
|
|
%
|
|
\membersection{wxSocketBase::WaitForRead}\label{wxsocketbasewaitforread}
|
|
|
|
\func{bool}{WaitForRead}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
|
|
|
|
This function waits for a read event.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{seconds}{Number of seconds to wait. By default, it waits infinitely.}
|
|
|
|
\docparam{millisecond}{Number of milliseconds to wait.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns TRUE if a byte arrived, FALSE if the timeout was reached.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::Wait}{wxsocketbasewait}\\
|
|
\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}\\
|
|
\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
|
|
|
|
%
|
|
% WaitForWrite
|
|
%
|
|
\membersection{wxSocketBase::WaitForWrite}\label{wxsocketbasewaitforwrite}
|
|
|
|
\func{bool}{WaitForWrite}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
|
|
|
|
This function waits for a write event.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{seconds}{Number of seconds to wait. By default, it waits infinitely.}
|
|
|
|
\docparam{millisecond}{Number of milliseconds to wait.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns TRUE if a write event occured, FALSE if the timeout was reached.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::Wait}{wxsocketbasewait}\\
|
|
\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}\\
|
|
\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
|
|
|
|
%
|
|
% WaitForLost
|
|
%
|
|
\membersection{wxSocketBase::WaitForLost}\label{wxsocketbasewaitforlost}
|
|
|
|
\func{bool}{Wait}{\param{long}{ seconds = -1}, \param{long}{ millisecond = 0}}
|
|
|
|
This function waits for a "lost" event. For instance, the peer may have closed
|
|
the connection, or the connection may have been broken.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{seconds}{Number of seconds to wait. By default, it waits infinitely.}
|
|
|
|
\docparam{millisecond}{Number of milliseconds to wait.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns TRUE if a "lost" event occured, FALSE if the timeout was reached.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}\\
|
|
\helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}\\
|
|
\helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}
|
|
|
|
%
|
|
% RestoreState
|
|
%
|
|
\membersection{wxSocketBase::RestoreState}\label{wxsocketbaserestorestate}
|
|
|
|
\func{void}{RestoreState}{\void}
|
|
|
|
This function restores the previous state of the socket (include flags,
|
|
notify flags, notify state, C callback function and data).
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::SaveState}{wxsocketbasesavestate}
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% Socket state
|
|
% ---------------------------------------------------------------------------
|
|
%
|
|
% SaveState
|
|
%
|
|
\membersection{wxSocketBase::SaveState}\label{wxsocketbasesavestate}
|
|
|
|
\func{void}{SaveState}{\void}
|
|
|
|
This function saves the current state of the socket object in a stack:
|
|
actually it saves all flags and the state of the asynchronous callbacks.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::RestoreState}{wxsocketbaserestorestate}
|
|
|
|
%
|
|
% GetLocal
|
|
%
|
|
\membersection{wxSocketBase::GetLocal}{wxsocketbasegetlocal}
|
|
|
|
\constfunc{bool}{GetLocal}{\param{wxSockAddress\& }{addr_man}}
|
|
|
|
This function returns the local address field of the socket. The local
|
|
address field contains the complete local address of the socket (local
|
|
address, local port, ...).
|
|
|
|
\wxheading{Return value}
|
|
|
|
It returns TRUE if no errors happened, FALSE otherwise.
|
|
|
|
%
|
|
% GetPeer
|
|
%
|
|
\membersection{wxSocketBase::GetPeer}{wxsocketbasegetlocal}
|
|
|
|
\constfunc{bool}{GetPeer}{\param{wxSockAddress\& }{addr_man}}
|
|
|
|
This function returns the peer address field of the socket. The peer
|
|
address field contains the complete peer host address of the socket
|
|
(address, port, ...).
|
|
|
|
\wxheading{Return value}
|
|
|
|
It returns TRUE if no errors happened, FALSE otherwise.
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% Socket callbacks
|
|
% ---------------------------------------------------------------------------
|
|
\membersection{wxSocketBase::SetEventHandler}\label{wxsocketbaseseteventhandler}
|
|
|
|
\func{void}{SetEventHandler}{\param{wxEvtHandler\&}{ evt\_hdlr}, \param{int}{ id = -1}}
|
|
|
|
Sets an event handler to be called when a socket event occured.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{evt\_hdlr}{Specifies the event handler you want to use.}
|
|
|
|
\docparam{id}{The id of socket event.}
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}
|
|
\helpref{wxSocketBase::Notify}{wxsocketbasenotify}
|
|
\helpref{wxSocketEvent}{wxsocketevent}
|
|
\helpref{wxEvtHandler}{wxevthandler}
|
|
|
|
\membersection{wxSocketBase::Callback}\label{wxsocketbasecallback}
|
|
|
|
\func{wxSocketBase::wxSockCbk}{Callback}{\param{wxSocketBase::wxSockCbk}{ callback}}
|
|
|
|
wxSocket event handler can call C callback. This function allows you to set it.
|
|
The format of the callback is as followed:
|
|
\begin{verbatim}
|
|
void SocketCallback(wxSocketBase& sock,wxSocketNotify evt,char *cdata);
|
|
\end{verbatim}
|
|
|
|
The first parameter reminds you of the caller socket. The second parameter
|
|
informs you about the current event (See \helpref{wxSocket events}{wxsocketbase}).
|
|
The third parameters is the client data you specified using \helpref{CallbackData}{wxsocketcallbackdata}.
|
|
|
|
\wxheading{Return value}
|
|
|
|
It returns the previous callback.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::SetNotify}{wxsocketbasesetnotify}
|
|
\helpref{wxSocketBase::Notify}{wxsocketbasenotify}
|
|
|
|
\membersection{wxSocketBase::CallbackData}\label{wxsocketcallbackdata}
|
|
|
|
\func{char *}{CallbackData}{\param{char *}{cdata}}
|
|
|
|
This function sets the the client data which will be passed to a \helpref{C callback}{wxsocketbasecallback}.
|
|
|
|
\wxheading{Return value}
|
|
|
|
This function returns the old value of the client data pointer.
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% CLASS wxSocketClient
|
|
% ---------------------------------------------------------------------------
|
|
\section{\class{wxSocketClient}}\label{wxsocketclient}
|
|
|
|
\wxheading{Derived from}
|
|
|
|
\helpref{wxSocketBase}{wxsocketbase}
|
|
|
|
\wxheading{Include files}
|
|
|
|
<wx/socket.h>
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% Members
|
|
% ---------------------------------------------------------------------------
|
|
%
|
|
% wxSocketClient
|
|
%
|
|
\membersection{wxSocketClient::wxSocketClient}
|
|
|
|
\func{}{wxSocketClient}{\param{wxSockFlags}{ flags = wxSocketBase::NONE}}
|
|
|
|
Constructs a new wxSocketClient.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})}
|
|
|
|
%
|
|
% ~wxSocketClient
|
|
%
|
|
\membersection{wxSocketClient::\destruct{wxSocketClient}}
|
|
|
|
\func{}{\destruct{wxSocketClient}}{\void}
|
|
|
|
Destroys a wxSocketClient object.
|
|
|
|
%
|
|
% Connect
|
|
%
|
|
\membersection{wxSocketClient::Connect}\label{wxsocketclientconnect}
|
|
|
|
\func{bool}{Connect}{\param{wxSockAddress\&}{ address}, \param{bool}{ wait = TRUE}}
|
|
|
|
Connects to a server using the specified address. If {\it wait} is TRUE, Connect
|
|
will wait for the socket ready to send or receive data.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{address}{Address of the server.}
|
|
|
|
\docparam{wait}{If true, waits for the connection to be ready.}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns TRUE if the connection is established and no error occurs.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect}
|
|
|
|
%
|
|
% WaitOnConnect
|
|
%
|
|
\membersection{wxSocketClient::WaitOnConnect}\label{wxsocketclientwaitonconnect}
|
|
|
|
\func{bool}{WaitOnConnect}{\param{long}{ seconds = -1}, \param{long}{ milliseconds = 0}}
|
|
|
|
Wait for a "connect" event.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase::Wait}{wxsocketbasewait} for a detailed description.
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% CLASS: wxSocketEvent
|
|
% ---------------------------------------------------------------------------
|
|
\section{\class{wxSocketEvent}}\label{wxsocketevent}
|
|
|
|
This event class contains information about socket events.
|
|
|
|
\wxheading{Derived from}
|
|
|
|
\helpref{wxEvent}{wxevent}
|
|
|
|
\wxheading{Include files}
|
|
|
|
<wx/socket.h>
|
|
|
|
\wxheading{Event table macros}
|
|
|
|
To process a socket event, use these event handler macros to direct input to member
|
|
functions that take a wxSocketEvent argument.
|
|
|
|
\twocolwidtha{7cm}
|
|
\begin{twocollist}\itemsep=0pt
|
|
\twocolitem{{\bf EVT\_SOCKET(id, func)}}{Process a socket event, supplying the member function.}
|
|
\end{twocollist}%
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketBase}{wxsocketbase},\rtfsp
|
|
\helpref{wxSocketClient}{wxsocketclient},\rtfsp
|
|
\helpref{wxSocketServer}{wxsocketserver}
|
|
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
\membersection{wxSocketEvent::wxSocketEvent}
|
|
|
|
\func{}{wxSocketEvent}{\param{int}{ id = 0}}
|
|
|
|
Constructor.
|
|
|
|
\membersection{wxSocketEvent::SocketEvent}\label{wxsocketeventsocketevent}
|
|
|
|
\constfunc{wxSocketNotify}{SocketEvent}{\void}
|
|
|
|
Returns the socket event type.
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% CLASS: wxSocketServer
|
|
% ---------------------------------------------------------------------------
|
|
\section{\class{wxSocketServer}}\label{wxsocketserver}
|
|
|
|
\wxheading{Derived from}
|
|
|
|
\helpref{wxSocketBase}{wxsocketbase}
|
|
|
|
\wxheading{Include files}
|
|
|
|
<wx/socket.h>
|
|
|
|
% ---------------------------------------------------------------------------
|
|
% Members
|
|
% ---------------------------------------------------------------------------
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
%
|
|
% wxSocketServer
|
|
%
|
|
\membersection{wxSocketServer::wxSocketServer}\label{wxsocketserverconstr}
|
|
|
|
\func{}{wxSocketServer}{\param{wxSockAddress\&}{ address}, \param{wxSockFlags}{ flags = wxSocketBase::NONE}}
|
|
|
|
Constructs a new wxSocketServer.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{address}{Specifies the local address for the server (e.g. port number).}
|
|
|
|
\docparam{flags}{Socket flags (See \helpref{wxSocketBase::SetFlags}{wxsocketbasesetflags})}
|
|
|
|
%
|
|
% ~wxSocketServer
|
|
%
|
|
\membersection{wxSocketServer::\destruct{wxSocketServer}}
|
|
|
|
\func{}{\destruct{wxSocketServer}}{\void}
|
|
|
|
Destroys a wxSocketServer object (it doesn't close the accepted connection).
|
|
|
|
%
|
|
% Accept
|
|
%
|
|
\membersection{wxSocketServer::Accept}
|
|
|
|
\func{wxSocketBase *}{Accept}{\void}
|
|
|
|
Creates a new object wxSocketBase and accepts an incoming connection. {\bf Warning !} This function will block the GUI.
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns an opened socket connection.
|
|
|
|
\wxheading{See also}
|
|
|
|
\helpref{wxSocketServer::AcceptWith}{wxsocketserveracceptwith}
|
|
|
|
%
|
|
% AcceptWith
|
|
%
|
|
\membersection{wxSocketServer::AcceptWith}\label{wxsocketserveracceptwith}
|
|
|
|
\func{bool}{AcceptWith}{\param{wxSocketBase\&}{ socket}}
|
|
|
|
Accept an incoming connection using the specified socket object.
|
|
This is useful when someone wants to inherit wxSocketBase.
|
|
|
|
\wxheading{Parameters}
|
|
|
|
\docparam{socket}{Socket to be initialized}
|
|
|
|
\wxheading{Return value}
|
|
|
|
Returns TRUE if no error occurs, else FALSE.
|
|
|