Ошибка CAsyncSocket 10093

Я унаследовал от CAsyncSocket, реализовать свой собственный класс. Во-первых, это начинается так:

MyClient::MyClient()//this is the constructor, I will create the socket in this constructor
{
if (!Create(0, SOCK_DGRAM, FD_READ | FD_WRITE))
{
UINT errCode = GetLastError();
printf("Create Client socket failed! Errorcode is %d\n", errCode);
}
}

Но это отображает Create Client socket failed! Errorcode is 10093,

Я искал в Интернете, он показывает 10093 из-за:

Успешный запуск WSAS еще не выполнен.

Либо приложение не вызвало WSAStartup, либо произошел сбой WSAStartup. Приложение может получать доступ к сокету, который не принадлежит текущей активной задаче (то есть пытается разделить сокет между задачами), или WSACleanup вызывался слишком много раз.

Затем я пересматриваю свой код

MyClient::MyClient()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;

/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
wVersionRequested = MAKEWORD(2, 2);

err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
/* Tell the user that we could not find a usable */
/* Winsock DLL.                                  */
printf("WSAStartup failed with error: %d\n", err);

}

/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater    */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we      */
/* requested.                                        */

if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
/* Tell the user that we could not find a usable */
/* WinSock DLL.                                  */
printf("Could not find a usable version of Winsock.dll\n");
WSACleanup();

}
else
printf("The Winsock 2.2 dll was found okay\n");/* The Winsock DLL is acceptable. Proceed to use it. */

/* Add network programming using Winsock here */

/* then call WSACleanup when done using the Winsock dll */if (!Create(0, SOCK_DGRAM, FD_READ | FD_WRITE))
{
UINT errCode = GetLastError();
printf("Create Client socket failed! Errorcode is %d\n", errCode);
}
WSACleanup();
}

Затем запустите его, он отображает:

образ

Я тоже пытался добавить

if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}

Но это все еще имеет ту же ошибку.

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector