jade03
asked on
socket error 10093 when trying to reconnect client
I have a socket connection going when my application starts up. Then the user can click on a button to change the port number that the application is connected to. When the button is clicked, I close the socket (CAsynSocket btw), and tried the following in trying to reconnect it, but keep getting error 10093 each time:
Ex: I have a socket:
CAsyncSocket *mySocket;
1) call connect() again // got 10093 error
2) call create()
then call connect() // same 10093 error
3) mySocket = new CAsyncSocket();
mySockiet->create()
mySocket->connect() // same 10093 error
My question: what happens after I close a socket? Do I need to do a complete clean up with WSACleanup() then call WSAStartup again? Does error 10093 mean WSAStartup is not being called?
Ex: I have a socket:
CAsyncSocket *mySocket;
1) call connect() again // got 10093 error
2) call create()
then call connect() // same 10093 error
3) mySocket = new CAsyncSocket();
mySockiet->create()
mySocket->connect() // same 10093 error
My question: what happens after I close a socket? Do I need to do a complete clean up with WSACleanup() then call WSAStartup again? Does error 10093 mean WSAStartup is not being called?
ASKER
yes, I realized that was probably the error...but my question is, I had called that once already on the first connection, should I call it AGAIN after I close the socket in order to reconnect?
>>should I call it AGAIN after I close the socket in order to reconnect?
You don't need to call 'AfxSocketInit ()'/'WSAStartup()' unless you called 'WSACleanup()'
You don't need to call 'AfxSocketInit ()'/'WSAStartup()' unless you called 'WSACleanup()'
ASKER
right...that's the thing...I didn't call WSACleanup() after I call close(), but still it won't let me do another connect()...so I'm trying to figure out why...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes, after fidgiting around with it for a while, it seems to work after I recall WSAStartup and then create() then connect(). Thank you!
The error is
#define WSANOTINITIALISED (WSABASEERR+93)
which indeed means that you forgot to
AfxSocketInit ();
or
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}