18,356
社区成员
发帖
与我相关
我的任务
分享
void CMyAsyncSocket::OnReceive(int nErrorCode) // CMyAsyncSocket is
// derived from CAsyncSocket
{
static int i=0;
i++;
TCHAR buff[4096];
int nRead;
nRead = Receive(buff, 4096);
switch (nRead)
{
case 0:
Close();
break;
case SOCKET_ERROR:
if (GetLastError() != WSAEWOULDBLOCK)
{
AfxMessageBox ("Error occurred");
Close();
}
break;
default:
buff[nRead] = 0; //terminate the string
CString szTemp(buff);
m_strRecv += szTemp; // m_strRecv is a CString declared
// in CMyAsyncSocket
if (szTemp.CompareNoCase("bye") == 0 ) ShutDown();
}
CAsyncSocket::OnReceive(nErrorCode);
}