CAsyncSocket::OnConnect

이 소켓에 연결 연결 시도, 오류에서 또는 성공적으로 완료 되었음을 알리기 위해 프레임 워크에서 호출 합니다.

virtual void OnConnect(
   int nErrorCode 
);

매개 변수

  • nErrorCode
    소켓에서 가장 최근 오류입니다.다음 오류 코드에 적용 된 OnConnect 멤버 함수:

    • 0 함수가 성공적으로 실행 합니다.

    • WSAEADDRINUSE 지정한 주소가 이미 사용 중입니다.

    • WSAEADDRNOTAVAIL 지정 된 주소는 로컬 컴퓨터에서 사용할 수 없습니다.

    • WSAEAFNOSUPPORT 주소에 지정 된 제품군이이 소켓을 사용할 수 없습니다.

    • WSAECONNREFUSED 연결 시도가 강제로 거부 되었습니다.

    • WSAEDESTADDRREQ 대상 주소입니다.

    • WSAEFAULT 의 lpSockAddrLen 인수가 잘못 되었습니다.

    • WSAEINVAL 소켓 주소가 이미 바인딩되어 있습니다.

    • WSAEISCONN 소켓이 이미 연결 되어 있습니다.

    • WSAEMFILE 없음 자세한 파일 설명자를 사용할 수 있습니다.

    • WSAENETUNREACH 네트워크에서이 호스트에 연결할 수 없습니다.

    • WSAENOBUFS버퍼 공간이 없습니다 사용할 수 있습니다.소켓을 연결할 수 없습니다.

    • WSAENOTCONN 소켓이 연결 되어 있지 않습니다.

    • WSAENOTSOCK 않은 소켓 파일 설명자입니다.

    • WSAETIMEDOUT 에 대 한 연결을 설정 하지 않고 연결 시도가 시간 초과.

설명

[!참고]

CSocket, OnConnect 알림 함수 호출입니다.단순히 호출 연결의 경우 연결, (성공적으로 또는 오류에서) 연결이 완료 되 면 반환 합니다.연결 알림을 처리 되는 MFC 구현의 세부 사항입니다.

자세한 내용은 Windows 소켓: 소켓 알림을.

예제

void CMyAsyncSocket::OnConnect(int nErrorCode)   // CMyAsyncSocket is 
                                                 // derived from CAsyncSocket
{
   if (0 != nErrorCode)
   {
      switch(nErrorCode)
      {
         case WSAEADDRINUSE: 
            AfxMessageBox(_T("The specified address is already in use.\n"));
            break;
         case WSAEADDRNOTAVAIL: 
            AfxMessageBox(_T("The specified address is not available from ")
            _T("the local machine.\n"));
            break;
         case WSAEAFNOSUPPORT: 
            AfxMessageBox(_T("Addresses in the specified family cannot be ")
            _T("used with this socket.\n"));
            break;
         case WSAECONNREFUSED: 
            AfxMessageBox(_T("The attempt to connect was forcefully rejected.\n"));
            break;
         case WSAEDESTADDRREQ: 
            AfxMessageBox(_T("A destination address is required.\n"));
            break;
         case WSAEFAULT: 
            AfxMessageBox(_T("The lpSockAddrLen argument is incorrect.\n"));
            break;
         case WSAEINVAL: 
            AfxMessageBox(_T("The socket is already bound to an address.\n"));
            break;
         case WSAEISCONN: 
            AfxMessageBox(_T("The socket is already connected.\n"));
            break;
         case WSAEMFILE: 
            AfxMessageBox(_T("No more file descriptors are available.\n"));
            break;
         case WSAENETUNREACH: 
            AfxMessageBox(_T("The network cannot be reached from this host ")
            _T("at this time.\n"));
            break;
         case WSAENOBUFS: 
            AfxMessageBox(_T("No buffer space is available. The socket ")
               _T("cannot be connected.\n"));
            break;
         case WSAENOTCONN: 
            AfxMessageBox(_T("The socket is not connected.\n"));
            break;
         case WSAENOTSOCK: 
            AfxMessageBox(_T("The descriptor is a file, not a socket.\n"));
            break;
         case WSAETIMEDOUT: 
            AfxMessageBox(_T("The attempt to connect timed out without ")
               _T("establishing a connection. \n"));
            break;
         default:
            TCHAR szError[256];
            _stprintf_s(szError, _T("OnConnect error: %d"), nErrorCode);
            AfxMessageBox(szError);
            break;
      }
      AfxMessageBox(_T("Please close the application"));
   }
   CAsyncSocket::OnConnect(nErrorCode);
}

요구 사항

헤더: afxsock.h

참고 항목

참조

CAsyncSocket 클래스

계층 구조 차트

CAsyncSocket::Connect

CAsyncSocket::GetLastError

CAsyncSocket::OnAccept

CAsyncSocket::OnClose

CAsyncSocket::OnOutOfBandData

CAsyncSocket::OnReceive

CAsyncSocket::OnSend