




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一,客户端程序:/ CClientView.cpp : implementation of the CCClientView class/#include stdafx.h#include CClient.h#include CClientDoc.h#include CClientView.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CCClientViewIMPLEMENT_DYNCREATE(CCClientView, CEditView)BEGIN_MESSAGE_MAP(CCClientView, CEditView)/AFX_MSG_MAP(CCClientView)ON_COMMAND(ID_BUTTON_CLOSE, OnButtonClose)ON_COMMAND(ID_BUTTON_CONNECT, OnButtonConnect)ON_COMMAND(ID_BUTTON_SEND, OnButtonSend)ON_UPDATE_COMMAND_UI(ID_BUTTON_CLOSE, OnUpdateButtonClose)ON_UPDATE_COMMAND_UI(ID_BUTTON_CONNECT, OnUpdateButtonConnect)ON_UPDATE_COMMAND_UI(ID_BUTTON_SEND, OnUpdateButtonSend)/AFX_MSG_MAP/ Standard printing commandsON_COMMAND(ID_FILE_PRINT, CEditView:OnFilePrint)ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView:OnFilePrint)ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView:OnFilePrintPreview)END_MESSAGE_MAP()/ CCClientView construction/destructionCCClientView:CCClientView()/ TODO: add construction code hereCCClientView:CCClientView()BOOL CCClientView:PreCreateWindow(CREATESTRUCT& cs)/ TODO: Modify the Window class or styles here by modifying/ the CREATESTRUCT csBOOL bPreCreated = CEditView:PreCreateWindow(cs);cs.style &= (ES_AUTOHSCROLL|WS_HSCROLL);/ Enable word-wrappingreturn bPreCreated;/ CCClientView drawingvoid CCClientView:OnDraw(CDC* pDC)CCClientDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data here/ CCClientView printingBOOL CCClientView:OnPreparePrinting(CPrintInfo* pInfo)/ default CEditView preparationreturn CEditView:OnPreparePrinting(pInfo);void CCClientView:OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)/ Default CEditView begin printing.CEditView:OnBeginPrinting(pDC, pInfo);void CCClientView:OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)/ Default CEditView end printingCEditView:OnEndPrinting(pDC, pInfo);/ CCClientView diagnostics#ifdef _DEBUGvoid CCClientView:AssertValid() constCEditView:AssertValid();void CCClientView:Dump(CDumpContext& dc) constCEditView:Dump(dc);CCClientDoc* CCClientView:GetDocument() / non-debug version is inlineASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CCClientDoc);return (CCClientDoc*)m_pDocument;#endif /_DEBUG/ CCClientView message handlersvoid CCClientView:OnButtonClose() / TODO: Add your command handler code herefor(int i = 0 ;i 200; i +)m_socki.ShutDown();void CCClientView:OnButtonConnect() / TODO: Add your command handler code herefor(int i = 0 ;i 200; i +)m_socki.Create();m_socki.SetView(this);m_socki.Connect(,2012);m_socki.m_bConnecting=TRUE;void CCClientView:OnButtonSend() / TODO: Add your command handler code herechar buffer256;wsprintf(buffer,How are you?);char *news;int len;int index = 0;news = GetNews(&len);CString msg = CString(news);for(int i = 0 ; i Enable(m_sock0.m_bConnected);void CCClientView:OnUpdateButtonConnect(CCmdUI* pCmdUI) / TODO: Add your command update UI handler code herepCmdUI-Enable(!m_sock0.m_bConnecting & !m_sock0.m_bConnected);void CCClientView:OnUpdateButtonSend(CCmdUI* pCmdUI) / TODO: Add your command update UI handler code herepCmdUI-Enable(m_sock0.m_bConnected);char * CCClientView:GetNews(int *plen)char *buff;CFile file;if(file.Open(msg.txt,CFile:modeRead)int len = file.GetLength();*plen = len + 1;buff = new charlen + 1;file.Read(buff,len);bufflen = 0;file.Close();return buff;二,服务器端/ CServerView.h : interface of the CCServerView class/#if !defined(AFX_CSERVERVIEW_H_B60CC748_3AF2_455B_A803_4F8BD05421E9_INCLUDED_)#define AFX_CSERVERVIEW_H_B60CC748_3AF2_455B_A803_4F8BD05421E9_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000inline void OutputMsg(CEditView* pView,LPCSTR msg)CString str;pView-GetEditCtrl().GetWindowText(str);pView-GetEditCtrl().SetWindowText(str+msg);class CProcessSocket : public CAsyncSocketCEditView* m_pView;virtual void OnReceive(int nErrorCode)char buffer256;int len=Receive(buffer,sizeof(buffer);bufferlen - 1 = 0;CString msg;msg.Format(Received message %s, length %d from %s. | ,buffer,len,m_addr);OutputMsg(m_pView,msg);wsprintf(buffer,Good, 谢谢!.);Send(buffer,sizeof(buffer);msg.Format(Request %s.rn,buffer);OutputMsg(m_pView,msg);virtual void OnClose(int nErrorCode)CString msg;msg.Format(Closed connection with %s.rn,m_addr);OutputMsg(m_pView,msg);/delete this;m_bIsClose = true;public:BOOL m_bIsClose;CString m_addr;CProcessSocket(CEditView* pView)m_pView=pView;class CWaitSocket : public CAsyncSocketCEditView* m_pView;virtual void OnAccept(int nErrorCode)for(int i = 0 ; i m_bIsClose = true)delete m_SocketListi;m_SocketList.RemoveAt(i);break;if(m_SocketList.GetSize() = 100) return;CProcessSocket *pSock = new CProcessSocket(m_pView);sockaddr_in client;int len=sizeof(client);Accept(*pSock,(sockaddr*)&client,&len);pSock-m_addr.Format(%s:%d,inet_ntoa(client.sin_addr),ntohs(client.sin_port);CString msg;msg.Format(Accepted connection from %s.rn,pSock-m_addr);OutputMsg(m_pView,msg);m_SocketList.Add(pSock);public:CArray m_SocketList;void SetView(CEditView* pView)m_pView=pView;CWaitSocket()for(int i = 0 ; i m_SocketList.GetSize() ; i + )delete m_SocketListi;class CCServerView : public CEditViewprotected: / create from serialization onlyCCServerView();DECLARE_DYNCREATE(CCServerView)/ Attributespublic:CCServerDoc* GetDocument();CWaitSocket m_sock;/ Operationspublic:/ Overrides/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CCServerView)public:virtual void OnDraw(CDC* pDC); / overridden to draw this viewvirtual BOOL PreCreateWindow(CREATESTRUCT& cs);protected:virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);/AFX_VIRTUAL/ Implementationpublic:virtual CCServerView();#ifdef _DEBUGvirtual void AssertValid() const;virtual void Dump(CDumpContext& dc) const;#endifprotected:/ Generated message map functionsprotected:/AFX_MSG(CCSe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 岗位标准化操作流程及管理规范
- 生活污水处理设备配置及安装方案
- 小学语文二年级下册期末测试卷
- 2025年吉林农业大学公开招聘急需紧缺人才岗位(3号)(6人)笔试备考试题及答案解析
- 2025年中国石油昆仑能源有限公司秋季高校毕业生招聘160人笔试模拟试题及答案解析
- 2025江苏南通如东县融媒体中心招聘专业技术人才2人笔试备考试题及答案解析
- 医院急救流程标准化操作指南
- 2025年疾病预防控制学流感疫情防控策略模拟考试卷答案及解析
- 中小学考试试题命制与评分标准
- 个人住房租赁合同风险提示
- 2025年合肥市轨道交通集团有限公司第二批次社会招聘12人考试历年参考题附答案详解
- 甘肃电网考试题目及答案
- 2025年专升本医学影像检查技术试题(含参考答案)解析
- 《互联网应用新特征》课件+2025-2026学年人教版(2024)初中信息技术七年级全一册
- 过节前安全培训课件
- 高二生物上学期第一次月考(安徽专用)(全解全析)
- 模具安全操作注意培训课件
- 3.2《参与民主生活 》- 课件 2025-2026学年度道德与法治九年级上册 统编版
- 农产品电子商务运营 教学大纲、教案
- 2025年秋新北师大版数学2年级上册全册同步教学设计
- 抖音短视频签约合同范本
评论
0/150
提交评论