Solved

Assertion on CSocketFile construction

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 80
Macro to save highlighted rows as a separate file 5 45
noX challenge 17 129
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 834
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…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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