2010년 5월 24일 월요일

윈도우7에서 "socket()" 함수가 -1 떨굴때/ socket() function returns -1 on windows7

Simon says.......Computer does not lie...


When you make command-line programming using visual studio rather then using automated MFC classes, you may encounter socket error that always returns -1 on "socket()" function call.

Following codes are required on intiali functions such as "main()"

    int nErrorStatus;
    WORD wVersionRequested = MAKEWORD(2, 2);
    WSADATA wsaData;

    nErrorStatus = WSAStartup(wVersionRequested, &wsaData);
    if(nErrorStatus!=0)
    {
        printf("WSAStartup failed\n");
    }


Also, when you make it clear, you can use following code.

    WSACleanup();

댓글 없음:

댓글 쓰기