ClientSocket.h ClientSocket.cpp
Posted qiwu1314
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
以上是关于ClientSocket.h ClientSocket.cpp的主要内容,如果未能解决你的问题,请参考以下文章