📄 csimplesocket.html
字号:
<html><head><title>CSimpleSocket Documentation</title></head>
<body><h1>
<a name="topofdoc"><img src="logo.gif">CSimpleSocket</a></h1>
<dl>
<dd>
Implements a socket class with additional features: timer, text protocol...
</dl>
<hr><p></p>
<p><strong>[
<a href="SimpleEmailClient.html">SimpleEmailClient</a> |
<a href="SimpleSocket.h">Source</a> |
<a href="/keyweb.html">Keywords</a> |
<a href="#aag">Summary</a> | <a href="#parents">Ancestors</a> | <a href="#flat">All Members</a> | <a href="#children">Descendants</a> ]</strong><p>
<h2><a name="quickind">Quick Index</a></h2>
<dl>
<dd><a href="#DESCRIPTION">DESCRIPTION</a>
<dd><a href="#USAGE">USAGE</a>
<dd><a href="#EXAMPLE">EXAMPLE</a>
<dd><a href="#ADMINISTRATIVE">ADMINISTRATIVE</a>
<dd><a href="#SEE_ALSO">SEE ALSO</a>
</dl>
<a name="aag"><hr><p></p></a><h2>Class Summary</h2>
class CSimpleSocket : public CSocket<br>
<br>
{
<br>
<br><i><b>public</b></i>:
<dl>
<dd>BOOL <a href="CSimpleSocket.html#BOOL_Connect(_LPCTSTR_lpszHostAddress,_UINT_nHostPort,_UINT_uTimeOut_)$"><font color=green>Connect</font></a>( LPCTSTR lpszHostAddress, UINT nHostPort, UINT uTimeOut );
<dd><a href="CSimpleSocket.html#CSimpleSocket(UINT_uTimeOut_)$"><font color=green>CSimpleSocket</font></a>(UINT uTimeOut );
<dd>~<a href="CSimpleSocket.html#~CSimpleSocket()$"><font color=green>CSimpleSocket</font></a>();
<dd>int <a href="CSimpleSocket.html#int_ReceiveString(CString&$_str,_int_nFlags_)$"><font color=green>ReceiveString</font></a>(CString& str, int nFlags );
<dd>int <a href="CSimpleSocket.html#int_ReceiveLine(CString&$_szLine,_int_nFlags_)$"><font color=green>ReceiveLine</font></a>(CString& szLine, int nFlags );
<dd>int <i><a href="CSimpleSocket.html#int_Receive(void*_lpBuf,_int_nBufLen,_int_nFlags_)$"><font color=green>Receive</font></a></i>(void* lpBuf, int nBufLen, int nFlags );
<dd>int <i><a href="CSimpleSocket.html#int_Send(const_void*_lpBuf,_int_nBufLen,_int_nFlags_)$"><font color=green>Send</font></a></i>(const void* lpBuf, int nBufLen, int nFlags );
<dd>int <i><a href="CSimpleSocket.html#int_Send(CString_&$szString,_int_nFlags_)$"><font color=green>Send</font></a></i>(CString &szString, int nFlags );
<dd>int <i><a href="CSimpleSocket.html#int_Send(LPCTSTR_lpszString,_int_nFlags_)$"><font color=green>Send</font></a></i>(LPCTSTR lpszString, int nFlags );
<dd>void <a href="CSimpleSocket.html#void_SetTimeOut(UINT_uTimeOut_)$"><font color=green>SetTimeOut</font></a>(UINT uTimeOut );
<dd>UINT <a href="CSimpleSocket.html#UINT_GetTimeOut()_const$"><font color=green>GetTimeOut</font></a>() const;
</dl>
<i><b>protected</b></i>:
<dl>
</dl>
}; // CSimpleSocket <p>
<p>Back to the <a href="#topofdoc">top</a> of <i>CSimpleSocket</i><p>
<a name="DESCRIPTION"><hr><p></p></a><h3>DESCRIPTION</h3>
<p>
This class provides an API for accessing Windows Socket similar
to the MFC CSocket class, but with additional features:
<UL>
<LI>Timer on all operations (Connect, Send, Receive)
<LI>Text Protocol Handling: new functions to receive text/lines
(suitable for text protocols like SMTP).
</UL>
<p>
<U><B>CAUTION:</B></U> do not share instances of this class between threads.
This class is derived from CSocket is suffers the same limitations
as its base class (as described in MSDN articles Q175668 and Q140527).
<p>
<p>Back to the <a href="#topofdoc">top</a> of <i>CSimpleSocket</i><p>
<a name="USAGE"><hr><p></p></a><h3>USAGE</h3>
<p>
To use this class:
<UL>
<LI>Create an instance of the class
<LI>Call method Create() [inherited]
<LI>Call method <a href="#BOOL_Connect(_LPCTSTR_lpszHostAddress,_UINT_nHostPort,_UINT_uTimeOut_)$">Connect</a>() [inherited]
<LI>Call either method <a href="#int_Send(CString_&$szString,_int_nFlags_)$">Send</a>(), <a href="#int_ReceiveString(CString&$_str,_int_nFlags_)$">ReceiveString</a>(), or <a href="#int_ReceiveLine(CString&$_szLine,_int_nFlags_)$">ReceiveLine</a>()
</UL>
<p>
<p>Back to the <a href="#topofdoc">top</a> of <i>CSimpleSocket</i><p>
<a name="EXAMPLE"><hr><p></p></a><h3>EXAMPLE</h3>
<p>
<PRE>
// Create an instance
CSimpleSocket oSocket;
<p>
// Create the socket
if (oSocket.Create())
{
// Connect to the server
if (oSocket.<a href="#BOOL_Connect(_LPCTSTR_lpszHostAddress,_UINT_nHostPort,_UINT_uTimeOut_)$">Connect</a>(m_szServerName, m_uPortNumber)!=0)
{
// Set timeout value to 30 seconds
oSocket.<a href="#void_SetTimeOut(UINT_uTimeOut_)$">SetTimeOut</a>(30000);
<p>
CString strResponse;
// Read response from the server
if (oSocket.<a href="#int_ReceiveLine(CString&$_szLine,_int_nFlags_)$">ReceiveLine</a>(strResponse) != SOCKET_ERROR) {
<p>
// Send data to server
oSocket.<a href="#int_Send(CString_&$szString,_int_nFlags_)$">Send</a>("QUIT\r\n");
<p>
}
}
}
<p>
// socket is closed automatically when the object oSocket is deleted.
<p>
</PRE>
<p>
<p>
<p>Back to the <a href="#topofdoc">top</a> of <i>CSimpleSocket</i><p>
<a name="ADMINISTRATIVE"><hr><p></p></a><h3>ADMINISTRATIVE</h3>
<p>
Author Emmanuel KARTMANN
<p>
Date Tuesday 11/17/98
<p>
<p>Back to the <a href="#topofdoc">top</a> of <i>CSimpleSocket</i><p>
<a name="SEE_ALSO"><hr><p></p></a><h3>SEE ALSO</h3>
<p>
CSocket CAsyncSocket<BR>
MSDN articles Q175668 and Q140527
<p>
<p>Back to the <a href="#topofdoc">top</a> of <i>CSimpleSocket</i><p>
<a name="BOOL_Connect(_LPCTSTR_lpszHostAddress,_UINT_nHostPort,_UINT_uTimeOut_)$"><hr><p></p><h3>BOOL Connect( LPCTSTR lpszHostAddress, UINT nHostPort, UINT uTimeOut );</h3></a>
<p>
<U>Purpose:</U> establish a connection to an unconnected stream
or datagram socket.
<p>
<U>Parameters:</U>
<p>
<dl><dl>
<dt><i>in</i><strong> lpszHostAddress</strong>
<dd> network address of the socket to which this object
is connected: a machine name such as
"ftp.microsoft.com", or a dotted number such as
"128.56.22.8".
<dt><i>in</i><strong> nHostPort</strong>
<dd> The port identifying the socket application
<dt><i>in</i><strong> uTimeOut</strong>
<dd> timeout value (in milliseconds)
<p>
</dl></dl>
<U>Return value :</U> BOOL = TRUE for success, FALSE otherwise.
<p>
<U>Description :</U> overrides CAsyncSocket::Connect
(implements timer with multithreading)
<p>
<p><pre>
BOOL <a href="#BOOL_Connect(_LPCTSTR_lpszHostAddress,_UINT_nHostPort,_UINT_uTimeOut_)$">Connect</a>( LPCTSTR lpszHostAddress, UINT nHostPort, UINT uTimeOut = INFINITE);
</pre>
<br><p>Back to the <a href="#topofdoc">top</a> of <i> CSimpleSocket </i> <p>
<a name="CSimpleSocket(UINT_uTimeOut_)$"><hr><p></p><h3>CSimpleSocket(UINT uTimeOut );</h3></a>
<p>
<U>Purpose:</U> create an instance of the class
<p>
<U>Parameters:</U>
<p>
<dl><dl>
<dt><i>in</i><strong> uTimeOut</strong>
<dd> default timeout value (in milliseconds)
<p>
</dl></dl>
<U>Return value :</U> none (C++ constructor)
<p>
<U>Description :</U>
<p>
<p><pre>
<a href="#CSimpleSocket(UINT_uTimeOut_)$">CSimpleSocket</a>(UINT uTimeOut = 0);
</pre>
<br><p>Back to the <a href="#topofdoc">top</a> of <i> CSimpleSocket </i> <p>
<a name="~CSimpleSocket()$"><hr><p></p><h3>~CSimpleSocket();</h3></a>
<p>
<U>Purpose:</U> delete an instance of the class
<p>
<U>Parameters:</U> none (C++ destructor)
<p>
<U>Return value :</U> none (C++ destructor)
<p>
<U>Description :</U>
<p>
<p><pre>
~CSimpleSocket();
</pre>
<br><p>Back to the <a href="#topofdoc">top</a> of <i> CSimpleSocket </i> <p>
<a name="int_ReceiveString(CString&$_str,_int_nFlags_)$"><hr><p></p><h3>int ReceiveString(CString& str, int nFlags );</h3></a>
<p>
<U>Purpose:</U> receives data (string only) from the socket.
<p>
<U>Parameters:</U>
<p>
<dl><dl>
<dt><i>in</i><strong> nFlags</strong>
<dd> option flag (same as for CSocket::<a href="#int_Receive(void*_lpBuf,_int_nBufLen,_int_nFlags_)$">Receive</a>())
<dt><i>out</i><strong> str</strong>
<dd> the string received from socket
<p>
</dl></dl>
<U>Return value :</U> int = number of bytes received in case of success,
SOCKET_ERROR otherwise.
<p>
<U>Description :</U> This function times out after (m_uTimeOut) milliseconds
<p>
<p><pre>
int <a href="#int_ReceiveString(CString&$_str,_int_nFlags_)$">ReceiveString</a>(CString& str, int nFlags = 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -