testacc1234
February 14th, 2008, 02:27 PM
Hi there,
I'm trying to build a MFC-based Client app using the CAsyncSocket class and I keep receiving this error when I
try to connect to the specified address and port. A portion of my code is provided below:
if (!AfxSocketInit())
//Display error
else
{
CClientSocket* pSock = new CClientSocket;
if (!pSock->Create())
{
//Display error
delete pSock;
}
//Else created socket
}
...
int nError;
const char *addr = "xxx.xxx.xxx.xxx";
if (!CAsyncSocket::Connect(addr, 3490))
{
nError = CAsyncSocket::GetLastError();
if (nError == WSAEWOULDBLOCK)
//Asynchronous Attempt started
else
//Display error -THIS IS WHERE I GET TO!
}
This is where I keep receiving the (WSAENOTSOCK The descriptor is not a socket. - 10038) error. I have debugged it all the way to the point where ConnectHelper() is called and the returned m_hSocket handle is invalid. The SockAddr structures are getting filled correctly too. I really don't understand what I'm doing wrong. The included header file is <afxsock.h>. I know that the server is working because I have another test program (client) that uses the <winsock2.h> file, the server can communicate with the client. I really need some help. Thanks in advance.
I'm trying to build a MFC-based Client app using the CAsyncSocket class and I keep receiving this error when I
try to connect to the specified address and port. A portion of my code is provided below:
if (!AfxSocketInit())
//Display error
else
{
CClientSocket* pSock = new CClientSocket;
if (!pSock->Create())
{
//Display error
delete pSock;
}
//Else created socket
}
...
int nError;
const char *addr = "xxx.xxx.xxx.xxx";
if (!CAsyncSocket::Connect(addr, 3490))
{
nError = CAsyncSocket::GetLastError();
if (nError == WSAEWOULDBLOCK)
//Asynchronous Attempt started
else
//Display error -THIS IS WHERE I GET TO!
}
This is where I keep receiving the (WSAENOTSOCK The descriptor is not a socket. - 10038) error. I have debugged it all the way to the point where ConnectHelper() is called and the returned m_hSocket handle is invalid. The SockAddr structures are getting filled correctly too. I really don't understand what I'm doing wrong. The included header file is <afxsock.h>. I know that the server is working because I have another test program (client) that uses the <winsock2.h> file, the server can communicate with the client. I really need some help. Thanks in advance.