//************************TALKCDlg.h________________________客户端
// TALKCDlg.h : 头文件
//
#if !defined(AFX_TALKCDLG_H__AC4F7955_1012_4B99_946D_E63FFC0AD185__INCLUDED_)
#define AFX_TALKCDLG_H__AC4F7955_1012_4B99_946D_E63FFC0AD185__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "afxwin.h"
#include "MySocket.h"
/
// CTALKCDlg 对话框
class CTALKCDlg : public CDialogEx
{
// 构造
public:
//CMySocket m_sConnectSocket;
CTALKCDlg(CWnd* pParent = NULL); // 标准构造函数
// 对话框数据
enum { IDD = IDD_TALKC_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
HICON m_hIcon;
// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
//控件变量
CString m_strServIP;
int m_nServPort;
CButton m_btnConnect;
CString m_strMsg;
CListBox m_listReceived;
CListBox m_listSend;
CMySocket m_sListenSocket;
CMySocket m_sConnectSocket;
//四个函数
void OnClose(void);
void OnConnect(void);
void OnReceive(void);
void OnSend(void);
afx_msg void OnBnClickedButtonConnet();
afx_msg void OnBnClickedButtonSend();
};
#endif // !defined(AFX_TALKCDLG_H__AC4F7955_1012_4B99_946D_E63FFC0AD185__INCLUDED_)
//*****************************TALKCDlg.cpp
// TALKCDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "TALKC.h"
#include "TALKCDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CTALKCDlg 对话框
CTALKCDlg::CTALKCDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CTALKCDlg::IDD, pParent)
, m_strServIP(_T("localhost"))
, m_nServPort(1000)
, m_strMsg(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTALKCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_SERVIP, m_strServIP);
DDX_Text(pDX, IDC_EDIT_SERVPORT, m_nServPort);
DDX_Text(pDX, IDC_EDIT_SERVIP, m_strServIP);
DDX_Text(pDX, IDC_EDIT_SERVPORT, m_nServPort);
DDX_Control(pDX, IDC_BUTTON_CONNET, m_btnConnect);
DDX_Text(pDX, IDC_EDIT_MSG, m_strMsg);
DDX_Control(pDX, IDC_LIST_RECEIVED, m_listReceived);
DDX_Control(pDX, IDC_LIST_SEND, m_listSend);
}
BEGIN_MESSAGE_MAP(CTALKCDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_CONNET, &CTALKCDlg::OnBnClickedButtonConnet)
ON_BN_CLICKED(IDC_BUTTON_SEND, &CTALKCDlg::OnBnClickedButtonSend)
END_MESSAGE_MAP()
// CTALKCDlg 消息处理程序
BOOL CTALKCDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 将“关于...”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
m_strServIP="localhost";
m_nServPort=1000;
UpdateData(TRUE);
m_sConnectSocket.SetParent(this);
// TODO: 在此添加额外的初始化代码
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void CTALKCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CTALKCDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CTALKCDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CTALKCDlg::OnClose(void)
{
m_sConnectSocket.Close();
}
void CTALKCDlg::OnConnect(void)
{
m_listReceived.AddString("客户机收到了onconnect消息");
}
void CTALKCDlg::OnReceive(void)
{
char *pBuf=new char[1025];
int nBufSize=1024;
int nReceived;
CString strReceived;
m_listReceived.AddString("客户机收到了OnReceive消息");
nReceived=m_sConnectSocket.Receive(pBuf,nBufSize);//receive the message
if (nReceived!=SOCKET_ERROR)//receive successfully?
{
pBuf[nReceived]=NULL;//truncate the end of the message
strReceived=pBuf;//copy the message to a CString
m_listReceived.AddString(strReceived);//add the message to the received list box
UpdateData(FALSE);//Update the dialog
}
else
{
AfxMessageBox("信息接收错误!",MB_OK|MB_ICONSTOP);
}
}
void CTALKCDlg::OnSend(void)
{
int nLen;//length of message
int nSent;//length of message been sent
UpdateData(TRUE);//retrive data from dialog
if (!m_strMsg.IsEmpty())//any message to be sent?
{
nLen=m_strMsg.GetLength();//get length of the message
nSent=m_sConnectSocket.Send(LPCTSTR(m_strMsg),nLen);//send the message
if (nSent!=SOCKET_ERROR)//send successfully?
{
m_listSend.AddString(m_strMsg);//add the message to the sent list box
UpdateData(FALSE);//update the dialog
}
else
{
AfxMessageBox("信息发送错误!",MB_OK|MB_ICONSTOP);
}
m_strMsg.Empty();//clear the current message
UpdateData(FALSE);//update the dailog
}
}
void CTALKCDlg::OnBnClickedButtonConnet()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
m_sConnectSocket.Create();
m_sConnectSocket.Connect(m_strServIP,m_nServPort);
}
void CTALKCDlg::OnBnClickedButtonSend()
{
// TODO: 在此添加控件通知处理程序代码
int nLen;//length of message
int nSent;//length of message been sent
UpdateData(TRUE);//retrive data from dialog
if (!m_strMsg.IsEmpty())//any message to be sent?
{
nLen=m_strMsg.GetLength();//get length of the message
nSent=m_sConnectSocket.Send(LPCTSTR(m_strMsg),nLen);//send the message
}
if (nSent != SOCKET_ERROR)//send successfully?
{
m_listSend.AddString(m_strMsg);//add the message to the sent list box
UpdateData(FALSE);//update the dialog
}
else
{
AfxMessageBox("信息发送错误!", MB_OK | MB_ICONSTOP);
}
m_strMsg.Empty();//clear the current message
UpdateData(FALSE);//update the dialog
}
//套接字头文件
#if !defined(AFX_MYSOCKET_H__9741667D_315B_4915_BCDE_9F2125BA065C__INCLUDED_)
#define AFX_MYSOCKET_H__9741667D_315B_4915_BCDE_9F2125BA065C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CMySocket 命令目标
#pragma once
//CMySocket 命令目标
class CTALKCDlg;
/
class CMySocket : public CAsyncSocket
{
public:
CMySocket();
virtual ~CMySocket();
virtual void OnConnect(int nErrorCode);
virtual void OnSend(int nErrorCode);
virtual void OnReceive(int nErrorCode);
virtual void OnClose(int nErrorCode);
CTALKCDlg* m_pDlg;
void SetParent(CTALKCDlg* pDlg);
};
#endif // !defined(AFX_MYSOCKET_H__9741667D_315B_4915_BCDE_9F2125BA065C__INCLUDED_)
//***************套接字MySocket.cpp
// MySocket.cpp : 实现文件
//
#include "stdafx.h"
#include "TALKC.h"
#include "MySocket.h"
#include "TALKCDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CMySocket
CMySocket::CMySocket()
: m_pDlg(NULL)
{
}
CMySocket::~CMySocket()
{
}
// CMySocket 成员函数
void CMySocket::OnConnect(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
if(nErrorCode==0)
m_pDlg->OnConnect();
//CAsyncSocket::OnConnect(nErrorCode);
}
void CMySocket::OnSend(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
if(nErrorCode==0)
m_pDlg->OnSend();
//CAsyncSocket::OnSend(nErrorCode);
}
void CMySocket::OnReceive(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
if(nErrorCode==0)
m_pDlg->OnReceive();
//CAsyncSocket::OnReceive(nErrorCode);
}
void CMySocket::OnClose(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
if(nErrorCode==0)
m_pDlg->OnClose();
//CAsyncSocket::OnClose(nErrorCode);
}
void CMySocket::SetParent(CTALKCDlg* pDlg)
{
m_pDlg = pDlg;
}
//***********************TALKSDlg.h_________________________服务器端
// TALKSDlg.h : 头文件
//
#if !defined(AFX_TALKSDLG_H__A13FF4B7_2D85_4211_81BC_2B11109251C0__INCLUDED_)
#define AFX_TALKSDLG_H__A13FF4B7_2D85_4211_81BC_2B11109251C0__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "afxwin.h"
#include "MySocket.h"
// CTALKSDlg 对话框
class CTALKSDlg : public CDialogEx
{
// 构造
public:
CTALKSDlg(CWnd* pParent = NULL); // 标准构造函数
// 对话框数据
enum { IDD = IDD_TALKS_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
HICON m_hIcon;
// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
//两个套接字
CMySocket m_sListenSocket;
CMySocket m_sConnectSocket;
//服务器ip和消息
CString m_strServIP;
CString m_strMsg;
//侦听按钮
CButton m_btnListen;
//显示消息的list
CListBox m_listReceive;
CListBox m_listSend;
//服务器端口
int m_nServPort;
//四个函数
void OnClose(void);
void OnAccept(void);
void OnReceive(void);
void OnConnect(void);
afx_msg void OnBnClickedButtonListen();
afx_msg void OnBnClickedButtonSend();
afx_msg void OnBnClickedButtonClose();
};
#endif // !defined(AFX_TALKSDLG_H__A13FF4B7_2D85_4211_81BC_2B11109251C0__INCLUDED_)
//**********************TALKSDlg.cpp
// TALKSDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "TALKS.h"
#include "TALKSDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CTALKSDlg 对话框
CTALKSDlg::CTALKSDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CTALKSDlg::IDD, pParent)
, m_strServIP(_T(""))
, m_strMsg(_T(""))
, m_nServPort(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTALKSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
//DDX_Control(pDX, IDC_EDIT_SERVIP, m_strServIP);
DDX_Text(pDX, IDC_EDIT_SERVIP, m_strServIP);
DDX_Text(pDX, IDC_EDIT_MSG, m_strMsg);
DDX_Control(pDX, IDC_BUTTON_LISTEN, m_btnListen);
DDX_Control(pDX, IDC_LIST_RECEIVE, m_listReceive);
DDX_Control(pDX, IDC_LIST_SEND, m_listSend);
DDX_Text(pDX, IDC_EDIT_SERVPORT, m_nServPort);
}
BEGIN_MESSAGE_MAP(CTALKSDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_LISTEN, &CTALKSDlg::OnBnClickedButtonListen)
ON_BN_CLICKED(IDC_BUTTON_SEND, &CTALKSDlg::OnBnClickedButtonSend)
ON_BN_CLICKED(IDC_BUTTON_CLOSE, &CTALKSDlg::OnBnClickedButtonClose)
END_MESSAGE_MAP()
// CTALKSDlg 消息处理程序
BOOL CTALKSDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 将“关于...”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
m_strServIP="localhost";
m_nServPort=1000;
UpdateData(FALSE);
m_sListenSocket.SetParent(this);
m_sConnectSocket.SetParent(this);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void CTALKSDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CTALKSDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CTALKSDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CTALKSDlg::OnAccept(void)
{
m_listReceive.AddString("服务器收到了OnAccept消息");
//to server
//accept the connection request
m_sListenSocket.Accept(m_sConnectSocket);
//enable the text and message controls
//GetDlgItem(IDC_EDIT_MSG)->EnableWindow(TRUE);
//GetDlgItem(IDOK)->EnableWindow(TRUE);//botton send
//GetDlgItem(IDC_STATIC_MSG)->EnableWindow(TRUE);
}
void CTALKSDlg::OnReceive(void)
{
char *pBuf=new char[1025];
int nBufSize=1024;
int nReceived;
CString strReceived;
m_listReceive.AddString("服务器收到了OnReceive消息");
//receive the message
nReceived=m_sConnectSocket.Receive(pBuf,nBufSize);
//receive successfully?
if(nReceived!=SOCKET_ERROR)
{
//truncate the end of the message
pBuf[nReceived]=NULL;
//copy the message to a CString
strReceived=pBuf;
//add the message to the received list box
m_listReceive.AddString(strReceived);
//Update the dialog
UpdateData(FALSE);
}
else
{
AfxMessageBox("信息接收错误!", MB_OK | MB_ICONSTOP);
}
}
void CTALKSDlg::OnConnect(void)
{
//to client
//enable the text and message controls
//enable the text and message controls
//GetDlgItem(IDC_EDIT_MSG)->EnableWindow(TRUE);
//GetDlgItem(IDOK)->EnableWindow(TRUE);//botton send
//GetDlgItem(IDC_STATIC_MSG)->EnableWindow(TRUE);
//close botton ready,only to client
//GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(TRUE);
m_listReceive.AddString("服务器收到了OnConnect消息");
}
//********************侦听按钮控件响应事件程序********************
void CTALKSDlg::OnBnClickedButtonListen()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
//disable the connection and type controls
//GetDlgItem(IDC_BUTTON_LISTEN)->EnableWindow(FALSE);
//GetDlgItem(IDC_EDIT_SERVIP)->EnableWindow(FALSE);
//GetDlgItem(IDC_EDIT_SERVPORT)->EnableWindow(FALSE);
//GetDlgItem(IDC_STATIC_SERVNAME)->EnableWindow(FALSE);
//GetDlgItem(IDC_STATIC_SERVPORT)->EnableWindow(FALSE);
//server,create a socket bound to the port specified
m_sListenSocket.Create(m_nServPort);
//listen for connection request
m_sListenSocket.Listen();
}
void CTALKSDlg::OnClose(void)
{
m_listReceive.AddString("服务器收到了OnClose消息");
//close the connected socket
m_sConnectSocket.Close();
//disable the message sending controls
//GetDlgItem(IDC_EDIT_MSG)->EnableWindow(FALSE);
//GetDlgItem(IDOK)->EnableWindow(FALSE);//botton send
//GetDlgItem(IDC_STATIC_MSG)->EnableWindow(FALSE);
//GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(FALSE);
//clear the list boxes
//while (m_listSend.GetCount() != 0)
// m_listSend.DeleteString(0);
//while (m_listReceive.GetCount() != 0)
//m_listReceive.DeleteString(0);
}
//********************发送按钮控件响应事件程序********************
void CTALKSDlg::OnBnClickedButtonSend()
{
// TODO: 在此添加控件通知处理程序代码
int nLen;//消息的长度
int nSent;//发送消息的长度
UpdateData(TRUE);
//任何信息都被发送吗?(信息不为空就发送出去)
if(!m_strMsg.IsEmpty())
{
//获得消息的长度
nLen=m_strMsg.GetLength();
//发送消息
nSent=m_sConnectSocket.Send(LPCSTR(m_strMsg),nLen);
//是否发送成功?
if(nSent!=SOCKET_ERROR)
{
//添加消息到listbox控件
m_listSend.AddString(m_strMsg);
//更新窗口
UpdateData(FALSE);
}
else
{
AfxMessageBox("信息发送错误");
}
//清空当前消息
m_strMsg.Empty();
//更新窗口
UpdateData(FALSE);
}
}
//********************断开按钮控件响应事件程序********************
void CTALKSDlg::OnBnClickedButtonClose()
{
// TODO: 在此添加控件通知处理程序代码
OnClose();
}
//**********************套接字MySocket.h
#pragma once
// CMySocket 命令目标
class CTALKSDlg;
class CMySocket : public CAsyncSocket
{
public:
CMySocket();
virtual ~CMySocket();
virtual void OnAccept(int nErrorCode);
virtual void OnClose(int nErrorCode);
virtual void OnConnect(int nErrorCode);
virtual void OnReceive(int nErrorCode);
CTALKSDlg* m_pDlg;
void SetParent(CTALKSDlg* pDlg);
};
//*************套接字MySocket.cpp
// MySocket.cpp : 实现文件
//
#include "stdafx.h"
#include "TALKS.h"
#include "MySocket.h"
#include "TALKSDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CMySocket
CMySocket::CMySocket()
: m_pDlg(NULL)
{
}
CMySocket::~CMySocket()
{
m_pDlg = NULL;
}
// CMySocket 成员函数
void CMySocket::OnAccept(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
if (nErrorCode == 0)
m_pDlg->OnAccept();
//CAsyncSocket::OnAccept(nErrorCode);
}
void CMySocket::OnClose(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
if (nErrorCode == 0)
m_pDlg->OnClose();
//CAsyncSocket::OnClose(nErrorCode);
}
void CMySocket::OnConnect(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
if (nErrorCode == 0)
m_pDlg->OnConnect();
//CAsyncSocket::OnConnect(nErrorCode);
}
void CMySocket::OnReceive(int nErrorCode)
{
// TODO: 在此添加专用代码和/或调用基类
if (nErrorCode == 0)
m_pDlg->OnReceive();
//CAsyncSocket::OnReceive(nErrorCode);
}
void CMySocket::SetParent(CTALKSDlg* pDlg)
{
m_pDlg = pDlg;
}