Solved

Assertion on CSocketFile construction

Posted on 2000-04-08
5
516 Views
Last Modified: 2013-11-20
Hi,
i have this code:

      CSocket sock;
      sock.Create();
      sock.Connect("localhost",80);
--->      CSocketFile file(&sock);
      CArchive in(&file,CArchive::load);
      CArchive out(&file,CArchive::store);

and i get this debug assertion on the marked line:
SOCKCORE.CPP, line 964:
      ASSERT(m_pSocket->m_hSocket != INVALID_SOCKET);

(m_pSocket is &sock)

and two other ones 4 lines later:
      ASSERT(m_pSocket->GetSockOpt(SO_TYPE,&nType,&nTypeLen));
      ASSERT(nType == SOCK_STREAM);

after that it crashes... of course the http server is running.
any clues?
0
Comment
Question by:Chris1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Expert Comment

by:sneedwt
ID: 2696612
Did you check the return code from the Connect & create calls?  The assertion you're getting basically states that the socket is not valid, thus the association is failing.  My guess is that the Sock Connect call is failing.  Try using the nErr=sock.GetLastError() and looking up the error code.  This might give us more info.
0
 

Author Comment

by:Chris1
ID: 2696688
Hey sneedwt,
yes there is a problem, but with .Create, GetLastError returns 10093 and of course connect fails, too (10022)
I traced it back to this line in CAsyncSocket::Socket():

m_hSocket = socket(nAddressFormat,nSocketType,nProtocolType);

(nAddressFormat=2; nSocketType=1; nProtocolType=0)

This fails (m_hSocket stays INVALID_SOCKET), but i don't know why...
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 2696825
Call the AfxSocketInit function in your CWinApp::InitInstance override to initialize Windows Sockets.
0
 
LVL 23

Expert Comment

by:chensu
ID: 2696826
The error code 10093 is WSANOTINITIALISED.
0
 

Author Comment

by:Chris1
ID: 2697462
Thanks, I forgot that =)
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

621 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