?
Solved

socket error 10093 when trying to reconnect client

Posted on 2005-04-22
6
Medium Priority
?
1,649 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:jade03
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 13845685
>>Does error 10093 mean WSAStartup is not being called?

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;
}
0
 

Author Comment

by:jade03
ID: 13846201
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?
0
 
LVL 86

Expert Comment

by:jkr
ID: 13846233
>>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()'
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jade03
ID: 13846267
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...
0
 
LVL 6

Accepted Solution

by:
nabehs earned 150 total points
ID: 13849021
I am not sure, but it seems that when you close the socket the socket state data is freed and on the destructor of the state data it calls AfxSocketTerm which class WSACleanup

_AFX_SOCK_STATE::~_AFX_SOCK_STATE()
{
      if (m_pfnSockTerm != NULL)
            m_pfnSockTerm();
}
 where m_pfnSockTerm points to AfxSocketTerm. This is my guess. so you need to re-call WSAStartup or AfxSocketInit again

0
 

Author Comment

by:jade03
ID: 13850717
yes, after fidgiting around with it for a while, it seems to work after I recall WSAStartup and then create() then connect(). Thank you!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question