ClientSocket.h ClientSocket.cpp

ClientSocket.h

 1 #pragma once
 2 
 3 // CClientSocket 命令目标
 4 #include "ClientProDlg.h"
 5 #include "afxsock.h"
 6 
 7 
 8 class CClientProDlg;
 9 
10 class CClientSocket : public CSocket    //从CSocket类派生一个用于处理接收Socket的类
11 {
12 
13 public:
14     CClientSocket(CClientProDlg *pdlg);    //获得应用程序的指针
15     virtual ~CClientSocket();
16     CClientProDlg *m_pDlg;
17     virtual void OnReceive(int nErrorCode);
18     virtual void OnClose(int nErrorCode);
19 
20 };

ClientSocket.cpp 

 1 // ClientSocket.cpp : implementation file
 2 //
 3 #include "stdafx.h"
 4 #include "ClientSocket.h"
 5 #include "ClientProDlg.h"
 6 
 7 CClientSocket::CClientSocket(CClientProDlg *pdlg)
 8     : m_pDlg(pdlg)
 9 {
10 }
11 
12 CClientSocket::~CClientSocket()
13 {
14 }
15 
16 void CClientSocket::OnReceive(int nErrorCode) 
17 {
18     if(m_pDlg)
19     {
20         m_pDlg->ReceiveData(this);
21     }
22     CSocket::OnReceive(nErrorCode);
23 }
24 void CClientSocket::OnClose(int nErrorCode)
25 {
26     if(m_pDlg)
27     {        
28         m_pDlg->ClientDisConnect(this);
29     }
30     CSocket::OnClose(nErrorCode);
31 }
32 // CClientSocket 成员函数

ClientProDlg.h中添加

#include "ClientSocket.h"

void ReceiveData(CClientSocket* socket);

void ClientDisConnect(CClientSocket* socket);

CClientSocket *m_pSocket;

posted @ 2018-10-10 11:48  小雨滴答  阅读(838)  评论(0编辑  收藏  举报