CAsyncSocket::OnReceive

virtual void OnReceive( int nErrorCode );

Parameters

nErrorCode

The most recent error on a socket. The following error codes apply to the OnReceive member function:

Remarks

Called by the framework to notify this socket that there is data in the buffer that can be retrieved by calling the Receive member function. For more information, see the article Windows Sockets: Socket Notifications in Visual C++ Programmer's Guide.

Example

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);
}

CAsyncSocket OverviewClass MembersHierarchy Chart

See Also   CAsyncSocket::GetLastError, CAsyncSocket::OnAccept, CAsyncSocket::OnClose, CAsyncSocket::OnConnect, CAsyncSocket::OnOutOfBandData, CAsyncSocket::OnSend, CAsyncSocket::Receive