Link to home
Start Free TrialLog in
Avatar of mruff
mruff

asked on

CSocket Getting Network failures

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?
Avatar of VEngineer
VEngineer


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?
Avatar of mruff

ASKER

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__
ASKER CERTIFIED SOLUTION
Avatar of VEngineer
VEngineer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial