- Notifications
You must be signed in to change notification settings - Fork 961
/
Copy pathcasyncsocket-class_2.cpp
36 lines (33 loc) · 783 Bytes
/
casyncsocket-class_2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
voidCMyAsyncSocket::OnReceive(int nErrorCode) // CMyAsyncSocket is
// derived from CAsyncSocket
{
staticint i = 0;
i++;
TCHAR buff[4096];
int nRead;
nRead = Receive(buff, 4096);
switch (nRead)
{
case0:
Close();
break;
case SOCKET_ERROR:
if (GetLastError() != WSAEWOULDBLOCK)
{
AfxMessageBox(_T("Error occurred"));
Close();
}
break;
default:
buff[nRead] = _T('\0'); //terminate the string
CString szTemp(buff);
m_strRecv += szTemp; // m_strRecv is a CString declared
// in CMyAsyncSocket
if (szTemp.CompareNoCase(_T("bye")) == 0)
{
ShutDown();
s_eventDone.SetEvent();
}
}
CAsyncSocket::OnReceive(nErrorCode);
}