Share via


CAsyncSocket::OnReceive

Llamado por el marco para notificar este socket que hay datos en el búfer que puede recuperar llamando a la función miembro de Recibir .

virtual void OnReceive(
   int nErrorCode 
);

Parámetros

  • nErrorCode
    el error más reciente en un socket.Los códigos de error siguientes se aplican a la función miembro de OnReceive :

    • Función de0 The ejecutada correctamente.

    • La implementación de Windows Sockets deWSAENETDOWN The detectó que produjo el subsistema de la red.

Comentarios

Para obtener más información, vea Windows Sockets: Notificaciones de socket.

Ejemplo

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

Requisitos

encabezado: afxsock.h

Vea también

Referencia

Clase de CAsyncSocket

Gráfico de jerarquía

CAsyncSocket::GetLastError

CAsyncSocket::OnAccept

CAsyncSocket::OnClose

CAsyncSocket::OnConnect

CAsyncSocket::OnOutOfBandData

CAsyncSocket::OnSend

CAsyncSocket::Receive