Accept() give me an assertion fail

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());
            TRACE("Communication accepted\n") ;

Can someone help me ?
Thanks in advance.
Who is Participating?
plarocheConnect With a Mentor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.