Solved

CSocket Getting Network failures

Posted on 1998-08-03
3
272 Views
Last Modified: 2013-11-19
I've got a Server app where n clients can connect. I'm using a CMySocket class (derived from CSocket). I've implemented the CMySocket::OnClose( int nErrorCode ) handler. there i got notifications whenever the client or the server are gone (not normally terminated)
My question: how can i get a notification when i.e. the network is down? i did the following: on computer B I run
a client and connected it to the Server (running on comp. A) on comp. A I pulled out the network connector (simulate network failure). None of my two callback functions (either OnReceive(int nErrorCode) nor OnClose( int nErrorCode ) have been called. so how can i get notified about this event?
0
Comment
Question by:mruff
[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
3 Comments
 
LVL 2

Expert Comment

by:VEngineer
ID: 1320163

I did the same thing as you did, except I derived from class CAsyncSocket.  When I broke the network connection, function OnClose was called.
I'm not sure why it wouldn't do the same for any class derived from CSocket.

Could you post your class MySocket definition (if it isn't exceedingly large) so we can take a look?
0
 

Author Comment

by:mruff
ID: 1320164
hello VEngineer,
here's the class interface definition:

// clntsock.h : interface of the CClientSocket class
//

#ifndef __CLNTSOCK_H__
#define __CLNTSOCK_H__

class CMsg;
class CWallPanelServerDoc;

class CClientSocket : public CSocket
{
      DECLARE_DYNAMIC(CClientSocket);
private:
      CClientSocket(const CClientSocket& rSrc);         // no implementation
      void operator=(const CClientSocket& rSrc);  // no implementation

// Construction
public:
      CClientSocket(CWallPanelServerDoc* m_pDoc);

// Attributes
public:
      int m_nMsgCount;
      CSocketFile* m_pFile;
      CArchive* m_pArchiveIn;
      CArchive* m_pArchiveOut;
      CWallPanelServerDoc* m_pDoc;
      BOOL IsAborted() { return m_pArchiveOut == NULL; }

// Operations
public:
      void Init();
      void Abort();
      void SendMsg(CMsg* pMsg);
      void ReceiveMsg(CMsg* pMsg);

// Overridable callbacks
protected:
      virtual void OnReceive(int nErrorCode);
      virtual void OnClose( int nErrorCode );

// Implementation
public:
      virtual ~CClientSocket();

#ifdef _DEBUG
      virtual void AssertValid() const;
      virtual void Dump(CDumpContext& dc) const;
#endif

};

#endif // __CLNTSOCK_H__
0
 
LVL 2

Accepted Solution

by:
VEngineer earned 50 total points
ID: 1320165
I think that the problem lies in the implementation of class CSocket (which is beyond your control).  CSocket switches between non-blocking (asyncronous) and blocking mode (syncronous) under certain circumstances.  This blocking in class CSocket means that the socket keeps waiting for a message and does not send a notification until it recieves one (and it doesn't since it disconnects).

What you have to do is either fool around with CSocket's attributes until you get it to do pure non-blocking, or an easier solution, derive your class from CAsyncSocket, which is known to work properly for your desired application.

I don't work with CSocket a lot, so I'm not sure how to resolve your problem if you want to modify CSocket attributes.  Maybe someone else out here can help you with that if that is your desired track.

If you have further questions, go ahead and stick more comments to the end of this and I'll try to answer them as best I can.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 200
Separate files macro - Errors on larger data set 18 73
sum67 challenge 35 116
matchUp  challenge 9 125
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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