Solved

Assertion on CSocketFile construction

Posted on 2000-04-08
5
507 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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