Solved

Accept() give me an assertion fail

Posted on 1998-10-23
1
321 Views
Last Modified: 2013-11-20
Hi,
I made two programs using the CSocket. When the server execute the Accept(), I have an assertion fail. If I ignore it, the communication works anyway but it's annoying. Here is the code

void CSockSvr::OnAccept(int nErrorCode)
{
      BOOL      Option = TRUE ;
      CString s ;

      if (m_Connection != NULL)
      {
            m_Connection->ShutDown(both) ;
            m_Connection->Close() ;
            delete m_Connection ;
      }
      m_Connection = new CSockCon ;
      m_Connection->Create() ;
      m_Connection->SetSockOpt(SO_REUSEADDR,&Option,sizeof(BOOL),SOL_SOCKET) ;

      if(!m_Server->Accept(*m_Connection))         // ASSERTION FAIL
      {
            s.Format("Error accepting the communication (%d).",GetLastError());
            AfxMessageBox(s);
      }
      else  
      {
            TRACE("Communication accepted\n") ;
      }
      
      //CSocket::OnAccept(nErrorCode);
}

Can someone help me ?
Thanks in advance.
0
Comment
Question by:kharandir
1 Comment
 
LVL 3

Accepted Solution

by:
plaroche earned 60 total points
Comment Utility
The socket you're passing to Accept() must not be "created". You do a new on it but no Create().

You may not be able to do a SetSockOpt() on it, I'm not sure. But that is why you get an ASSERT.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 85
Error on moodle after upgrade 3 105
unable to delete all specified values regedit 38 148
mapAB Challlenge 35 83
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now