Solved

Assertion on CSocketFile construction

Posted on 2000-04-08
5
468 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

19 Experts available now in Live!

Get 1:1 Help Now