|
-
February 14th, 2008, 03:27 PM
#1
CAsyncSocket::Connect() keeps returning WSAENOTSOCK The descriptor is not a socket.
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.
-
February 15th, 2008, 04:42 PM
#2
Re: CAsyncSocket::Connect() keeps returning WSAENOTSOCK The descriptor is not a socket.
try to bind the socket before the Connect(). Maybe that helps.
-
February 15th, 2008, 08:22 PM
#3
Re: CAsyncSocket::Connect() keeps returning WSAENOTSOCK The descriptor is not a socket.
Please post code that would compile. Yours obviously would not. For example, CAsyncSocket::Connect is a member function, not a static function, so this line of code makes no sense at all, and could notpossibly compile
Code:
if (!CAsyncSocket::Connect(addr, 3490))
Please also use [ code ][ /code ] tags to format you code neatly.
Mike
PS: for a client, there is no need to call bind() explicitly. The call to connect() implicitly binds the socket.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|