⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socket.tex

📁 wxWidgets 是一个跨平台的 GUI 框架。它给开发人员提供了统一的接口
💻 TEX
📖 第 1 页 / 共 3 页
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Name:        socket.tex%% Purpose:     wxSocket docs%% Author:      Guillermo Rodriguez Garcia <guille@iies.es>%% Modified by:%% Created:     1999%% RCS-ID:      $Id: socket.tex,v 1.48 2006/10/08 21:55:06 VZ Exp $%% Copyright:   (c) wxWidgets team%% License:     wxWindows license%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\section{\class{wxSocketBase}}\label{wxsocketbase}wxSocketBase is the base class for all socket-related objects, and itdefines all basic IO functionality.Note: (Workaround for implementation limitation for wxWidgets up to 2.5.x)If you want to use sockets or derived classes such as wxFTP in a secondary thread,call wxSocketBase::Initialize() (undocumented) from the main thread before creating any sockets - in wxApp::OnInit for example. See http://wiki.wxwidgets.org/wiki.pl?WxSocket orhttp://www.litwindow.com/knowhow/knowhow.html for more details.\wxheading{Derived from}\helpref{wxObject}{wxobject}\wxheading{Include files}<wx/socket.h>\wxheading{wxSocket errors}\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\_WOULDBLOCK}}{The socket is non-blocking and the operation would block.}\twocolitem{{\bf wxSOCKET\_TIMEDOUT}}{The timeout for this operation expired.}\twocolitem{{\bf wxSOCKET\_MEMERR}}{Memory exhausted.}\end{twocollist}\wxheading{wxSocket events}\twocolwidtha{7cm}\begin{twocollist}\itemsep=0pt\twocolitem{{\bf wxSOCKET\_INPUT}}{There is data available for reading.}\twocolitem{{\bf wxSOCKET\_OUTPUT}}{The socket is ready to be written to.}\twocolitem{{\bf wxSOCKET\_CONNECTION}}{Incoming connection request (server), or successful connection establishment (client).}\twocolitem{{\bf wxSOCKET\_LOST}}{The connection has been closed.}\end{twocollist}A brief note on how to use these events:The {\bf wxSOCKET\_INPUT} event will be issued whenever there is dataavailable for reading. This will be the case if the input queue wasempty and new data arrives, or if the application has read some datayet there is still more data available. This means that the applicationdoes not need to read all available data in response to a {\bf wxSOCKET\_INPUT} event, as more events will be produced asnecessary.The {\bf wxSOCKET\_OUTPUT} event is issued when a socket is firstconnected with \helpref{Connect}{wxsocketclientconnect} or acceptedwith \helpref{Accept}{wxsocketserveraccept}. After that, newevents will be generated only after an output operation failswith {\bf wxSOCKET\_WOULDBLOCK} and buffer space becomes availableagain. This means that the application should assume that itcan write data to the socket until an {\bf wxSOCKET\_WOULDBLOCK} error occurs; after this, whenever the socket becomes writableagain the application will be notified with another {\bf wxSOCKET\_OUTPUT} event.The {\bf wxSOCKET\_CONNECTION} event is issued when a delayed connectionrequest completes successfully (client) or when a new connection arrivesat the incoming queue (server).The {\bf wxSOCKET\_LOST} event is issued when a close indication isreceived for the socket. This means that the connection broke down orthat it was closed by the peer. Also, this event will be issued ifa connection request fails.\wxheading{Event handling}To process events coming from a socket object, use the following eventhandler macro to direct events to member functions that takea \helpref{wxSocketEvent}{wxsocketevent} argument.\twocolwidtha{7cm}%\begin{twocollist}\itemsep=0pt\twocolitem{{\bf EVT\_SOCKET(id, func)}}{Process a wxEVT\_SOCKET event.}\end{twocollist}\wxheading{See also}\helpref{wxSocketEvent}{wxsocketevent}, \helpref{wxSocketClient}{wxsocketclient}, \helpref{wxSocketServer}{wxsocketserver}, \helpref{Sockets sample}{samplesockets}% ---------------------------------------------------------------------------% Function groups% ---------------------------------------------------------------------------\latexignore{\rtfignore{\wxheading{Function groups}}}\membersection{Construction and destruction}\label{socketconstruction}\helpref{wxSocketBase}{wxsocketbaseconstruct}\\\helpref{\destruct{wxSocketBase}}{wxsocketbasedestruct}\\\helpref{Destroy}{wxsocketbasedestroy}\membersection{Socket state}\label{socketstate}Functions to retrieve current state and miscellaneous info.\helpref{Error}{wxsocketbaseerror}\\\helpref{GetLocal}{wxsocketbasegetlocal}\\\helpref{GetPeer}{wxsocketbasegetpeer}\helpref{IsConnected}{wxsocketbaseisconnected}\\\helpref{IsData}{wxsocketbaseisdata}\\\helpref{IsDisconnected}{wxsocketbaseisdisconnected}\\\helpref{LastCount}{wxsocketbaselastcount}\\\helpref{LastError}{wxsocketbaselasterror}\\\helpref{IsOk}{wxsocketbaseisok}\\\helpref{SaveState}{wxsocketbasesavestate}\\\helpref{RestoreState}{wxsocketbaserestorestate}\membersection{Basic IO}\label{socketbasicio}Functions that perform basic IO functionality.\helpref{Close}{wxsocketbaseclose}\\\helpref{Discard}{wxsocketbasediscard}\\\helpref{Peek}{wxsocketbasepeek}\\\helpref{Read}{wxsocketbaseread}\\\helpref{ReadMsg}{wxsocketbasereadmsg}\\\helpref{Unread}{wxsocketbaseunread}\\\helpref{Write}{wxsocketbasewrite}\\\helpref{WriteMsg}{wxsocketbasewritemsg}Functions that perform a timed wait on a certain IO condition.\helpref{InterruptWait}{wxsocketbaseinterruptwait}\\\helpref{Wait}{wxsocketbasewait}\\\helpref{WaitForLost}{wxsocketbasewaitforlost}\\\helpref{WaitForRead}{wxsocketbasewaitforread}\\\helpref{WaitForWrite}{wxsocketbasewaitforwrite}\\and also:\helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept}\\\helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect}Functions that allow applications to customize socket IO as needed.\helpref{GetFlags}{wxsocketbasegetflags}\\\helpref{SetFlags}{wxsocketbasesetflags}\\\helpref{SetTimeout}{wxsocketbasesettimeout}\\\helpref{SetLocal}{wxsocketbasesetlocal}\\\membersection{Handling socket events}\label{socketevents}Functions that allow applications to receive socket events.\helpref{Notify}{wxsocketbasenotify}\\\helpref{SetNotify}{wxsocketbasesetnotify}\\\helpref{GetClientData}{wxsocketbasegetclientdata}\\\helpref{SetClientData}{wxsocketbasesetclientdata}\\\helpref{SetEventHandler}{wxsocketbaseseteventhandler}% ---------------------------------------------------------------------------% Members here% ---------------------------------------------------------------------------\helponly{\insertatlevel{2}{\wxheading{Members}}}\membersection{wxSocketBase::wxSocketBase}\label{wxsocketbaseconstruct}\func{}{wxSocketBase}{\void}Default constructor. Don't use it directly; instead, use \helpref{wxSocketClient}{wxsocketclient} to construct a socket client, or \helpref{wxSocketServer}{wxsocketserver} to construct a socket server.\membersection{wxSocketBase::\destruct{wxSocketBase}}\label{wxsocketbasedestruct}\func{}{\destruct{wxSocketBase}}{\void}Destructor. Do not destroy a socket using the delete operator directly;use \helpref{Destroy}{wxsocketbasedestroy} instead. Also, do not createsocket objects in the stack.%% Close%\membersection{wxSocketBase::Close}\label{wxsocketbaseclose}\func{void}{Close}{\void}This function shuts down the socket, disabling further transmission andreception of data; it also disables events for the socket and frees theassociated system resources. Upon socket destruction, Close is automaticallycalled, so in most cases you won't need to do it yourself, unless youexplicitly want to shut down the socket, typically to notify the peerthat you are closing the connection.\wxheading{Remark/Warning}Although Close immediately disables events for the socket, it is possiblethat event messages may be waiting in the application's event queue. Theapplication must therefore be prepared to handle socket event messageseven after calling Close.%% Destroy%\membersection{wxSocketBase::Destroy}\label{wxsocketbasedestroy}\func{bool}{Destroy}{\void}Destroys the socket safely. Use this function instead of the delete operator,since otherwise socket events could reach the application even after thesocket has been destroyed. To prevent this problem, this function appendsthe wxSocket to a list of object to be deleted on idle time, after allevents have been processed. For the same reason, you should avoid creatingsocket objects in the stack.Destroy calls \helpref{Close}{wxsocketbaseclose} automatically.\wxheading{Return value}Always true.%% Discard%\membersection{wxSocketBase::Discard}\label{wxsocketbasediscard}\func{wxSocketBase\&}{Discard}{\void}This function simply deletes all bytes in the incoming queue. This functionalways returns immediately and its operation is not affected by IO flags.Use \helpref{LastCount}{wxsocketbaselastcount} to verify the number of bytes actually discarded.If you use \helpref{Error}{wxsocketbaseerror}, it will always return false.%% Error%\membersection{wxSocketBase::Error}\label{wxsocketbaseerror}\constfunc{bool}{Error}{\void}Returns true if an error occurred in the last IO operation.Use this function to check for an error condition after one of thefollowing calls: Discard, Peek, Read, ReadMsg, Unread, Write, WriteMsg.%% GetClientData%\membersection{wxSocketBase::GetClientData}\label{wxsocketbasegetclientdata}\constfunc{void *}{GetClientData}{\void}Returns a pointer of the client data for this socket, as set with \helpref{SetClientData}{wxsocketbasesetclientdata}%% GetLocal%\membersection{wxSocketBase::GetLocal}\label{wxsocketbasegetlocal}\constfunc{bool}{GetLocal}{\param{wxSockAddress\& }{addr}}This function returns the local address field of the socket. The localaddress field contains the complete local address of the socket (localaddress, local port, ...).\wxheading{Return value}true if no error happened, false otherwise.%% GetFlags%\membersection{wxSocketBase::GetFlags}\label{wxsocketbasegetflags}\constfunc{wxSocketFlags}{GetFlags}{\void}Returns current IO flags, as set with \helpref{SetFlags}{wxsocketbasesetflags}%% GetPeer%\membersection{wxSocketBase::GetPeer}\label{wxsocketbasegetpeer}\constfunc{bool}{GetPeer}{\param{wxSockAddress\& }{addr}}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}true if no error happened, false otherwise.%% InterruptWait%\membersection{wxSocketBase::InterruptWait}\label{wxsocketbaseinterruptwait}\func{void}{InterruptWait}{\void}Use this function to interrupt any wait operation currently in progress.Note that this is not intended as a regular way to interrupt a Wait call,but only as an escape mechanism for exceptional situations where it isabsolutely necessary to use it, for example to abort an operation due tosome exception or abnormal problem. InterruptWait is automatically calledwhen you \helpref{Close}{wxsocketbaseclose} a socket (and thus also uponsocket destruction), so you don't need to use it in these cases.\helpref{wxSocketBase::Wait}{wxsocketbasewait}, \helpref{wxSocketServer::WaitForAccept}{wxsocketserverwaitforaccept}, \helpref{wxSocketBase::WaitForLost}{wxsocketbasewaitforlost}, \helpref{wxSocketBase::WaitForRead}{wxsocketbasewaitforread}, \helpref{wxSocketBase::WaitForWrite}{wxsocketbasewaitforwrite}, \helpref{wxSocketClient::WaitOnConnect}{wxsocketclientwaitonconnect}%% IsConnected%\membersection{wxSocketBase::IsConnected}\label{wxsocketbaseisconnected}\constfunc{bool}{IsConnected}{\void}Returns true if the socket is connected.%% IsData%\membersection{wxSocketBase::IsData}\label{wxsocketbaseisdata}\constfunc{bool}{IsData}{\void}This function waits until the socket is readable. This might mean thatqueued data is available for reading or, for streamed sockets, thatthe connection has been closed, so that a read operation will completeimmediately without blocking (unless the {\bf wxSOCKET\_WAITALL} flagis set, in which case the operation might still block).\membersection{wxSocketBase::IsDisconnected}\label{wxsocketbaseisdisconnected}%% IsDisconnected%\constfunc{bool}{IsDisconnected}{\void}Returns true if the socket is not connected.\membersection{wxSocketBase::LastCount}\label{wxsocketbaselastcount}%% LastCount%\constfunc{wxUint32}{LastCount}{\void}Returns the number of bytes read or written by the last IO call.Use this function to get the number of bytes actually transferredafter using one of the following IO calls: Discard, Peek, Read,ReadMsg, Unread, Write, WriteMsg.%% LastError%\membersection{wxSocketBase::LastError}\label{wxsocketbaselasterror}\constfunc{wxSocketError}{LastError}{\void}Returns the last wxSocket error. See \helpref{wxSocket errors}{wxsocketbase}.Please note that this function merely returns the last error code,but it should not be used to determine if an error has occurred (thisis because successful operations do not change the LastError value).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -