網絡程序設計課程設計--vcmfc實現簡單的聊天室程序_第1頁
網絡程序設計課程設計--vcmfc實現簡單的聊天室程序_第2頁
網絡程序設計課程設計--vcmfc實現簡單的聊天室程序_第3頁
網絡程序設計課程設計--vcmfc實現簡單的聊天室程序_第4頁
網絡程序設計課程設計--vcmfc實現簡單的聊天室程序_第5頁
已閱讀5頁,還剩8頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、網絡程序設計課程設計-vc(mfc)實現簡單 的聊天室程序網絡程序設計課程設計-vc(mfc)實現簡單的聊天室程序 網絡程序設計 課程設計報告書題目: 簡單的聊天室程序專業:網絡工程完成日期:一、題目:簡單的聊天室程序 要求:本題是一個簡單的聊天 室程序,采用客戶/服務器模式,分為客戶端程序和服務器端 程序。由于服務器只能支持一個客戶,實際上是一個點對點通信 的程序??蛻舳顺绦蚝头掌鞒绦蛲ㄟ^網絡交換聊天字符串內容, 并在窗口的列表框中顯示。l。二、系統概要設計聊天室是分客戶端和服務端兩個應用程序的,兩個應用程序要想實現交互必須編寫相應的指令和識別指令的代碼,我寫的這是個指令依次是啟動停止用戶

2、退生 的命令,但用戶想要進行以上動作中的任何一個時,在用戶按下按鍵的時候,客戶端都是向服務端發送相應 的指令,再由服務端實際的執行。三、系統詳細設計 對概要設計中提到的功能函數進行詳 細設計。服務器端:/ ChatRoomServerDlg.cpp : implementation file / #include “stdafx.h“#include“ ChatRoomServer.h“#include“ ChatRoomServerDlg.h #include“ ListenSocket.h #ifdef_DEBUG #define new DEBUG_NEW #undef THIS_FIL

3、E static charTHIS_FILE口= FILE; #endif/CAboutDlg dialog used for App About class CAboutDlg : public CDialog public: CAboutDlg(); / Dialog Data AFX_DATA(CAboutDlg)enum IDD =IDD_ABOUTBOX ; AFX_DATA / ClassWizard generated virtual function overrides AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataE

4、xchange(CDataExchange* pDX); / DDX/DDV support /AFX_VIRTUAL / Implementation protected:AFX_MSG(CAboutDlg)/AFX_MSGDECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() :CDialog(CAboutDlg:IDD) /AFX_DATA_INIT(CAboutDlg) /AFX_DATA_INIT void CAboutDlg:DoDataExchange(CDataExchange* pDX) CDialog二DoDataExchange(pDX);

5、/AFX_DATA_MAP(CAboutDlg) /AFX_DATA_MAP BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)AFX_MSG_MAP(CAboutDlg)/ No message handlers/AFX_MSG_MAPEND_MESSAGE_MAP()/CChatRoomServerDlgdialogCChatRoomServerDlg:CChatRoomServerDlg(CWnd* pParent /*=NULL*/): CDialog(CChatRoomServerDlg:IDD, pParent) /AFX_DATA_INIT(CChatRoo

6、mServerDlg) / NOTE: theClassWizard will add member initialization here /AFX_DATA_INIT / Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon =AfxGetApp()->LoadIcon(IDR_MAINFRAME); voidCChatRoomServerDlg二DoDataExchange(CDataExchange*pDX)CDialog二DoDataExchange(pDX);/AFX_DAT

7、A_MAP(CChatRoomServerDlg)DDX_Control(pDX, m_IDC_BUTTON_STOP); IDC_BUTTON_START, /AFX_DATA_MAPBEGIN_MESSAGE_MAP(CChatRoomServerDlg,/AFX_MSG_MAP(CChatRoomServerDlg)IDC_BUTTON_STOP, DDX_Control(pDX, m_IDC_BUTTON_START);CDialog)ON_WM_PAINT()ON_WM_SYSCOMMAND()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON

8、_START, OnButtonStart) ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop) /AFX_MSG_MAPEND_MESSAGE_MAP()/CChatRoomServerDlg message handlers BOOL CChatRoomServerDlg:OnInitDialog() CDialog:OnInitDialog(); / Add “About. menu item to system menu. / IDM_ABOUTBOX must be in the system command range. ASSERT(IDM_

9、ABOUTBOX ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING , IDM_ABOUTBOX, strAboutMenu); / Set the icon for this dialog. The framework does this automatically / when the application s main window is not a dialog SetIcon(m_hIcon, TRUE);/ Set big icon SetIcon(m_hIcon, FA

10、LSE);/ Set small icon / TODO: Add extrainitializationherem_IDC_BUTTON_STOP.EnableWindow(FALSE);returnTRUE; / return TRUE unless you set the focus to a control void CChatRoomServerDlg二OnSysCommand(UINT nID, LPARAM lParam) if (nID dlgAbout.DoModal(); else CDialog:OnSysCommand(nID, lParam); / If you ad

11、d a minimize button to your dialog, you will need the code below /to draw the icon. For MFC applications using the document/view model, / this is automatically done for you by the framework. void CChatRoomServerDlg:OnPaint() if (IsIconic() CPaintDC dc(this); / device context for painting SendMessage

12、(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(), 0); / Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON);intcyIcon =GetSystemMetrics(SM_CYICON);CRectrect;GetClientRect( int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; / Draw the icon dc.DrawIcon(x,

13、 y, m_hIcon); else CDialog二OnPaint(); / The system calls this to obtain the cursor to display while the user drags / the minimizedwindow.HCURSORCChatRoomServerDlg:OnQueryDragIcon() return (HCURSOR)m_hIcon;voidCChatRoomServerDlg二OnButtonStart() / TODO: Add your control notification handler code here

14、m_IDC_BUTTON_START.EnableWindow(FALSE);/ 使啟動按 鈕無效 ListenSocket.Create(6767);/創建監聽套接字端口為 6767 ListenSocket.Listen();/ 開 始 監 聽 m_IDC_BUTTON_STOP.EnableWindow(TRUE);/ 將停止按鈕 激活 void CChatRoomServerDlg二OnButtonStop() / TODO:Addyourcontrol notification handler code herem_IDC_BUTTON_STOP.EnableWindow(FALSE

15、);/ 使停止按 鈕無效 ListenSocket.Close();/關閉監聽套接字 m_IDC_BUTTON_START.EnableWindow(TRUE);/ 將啟動按 鈕激活 / ChatRoomServer.h : main header file for the CHATROOMSERVERapplication/#if !defined(AFX_CHATROOMSERVER_H_680EC642_E19B_4D55_88DF_2C9E9B1B30FD INCLUDED_)#defineAFX_CHATROOMSERVER_H_680EC642_E19B_4D55_88DF_2C9

16、E9B1B30FD INCLUDED_#if _MSC_VER > 1000#pragma once #endif / _MSC_VER > 1000 #ifndefAFXWIN_H #error include stdafx.h before including this file for PCH #endif #include “resource.h ma/n symbols /CChatRoomServerApp: / See ChatRoomServer.cpp for the implementation of this class / class CChatRoomSe

17、rverApp : public CWinApp public: CChatRoomServerApp。; / Overrides / ClassWizard generated virtual function overrides /AFX_VIRTUAL(CChatRoomServerApp) public: virtual BOOL InitInstance(); /AFX_VIRTUAL / Implementation /AFX_MSG(CChatRoomServerApp) / NOTE - the ClassWizard will add and remove member fu

18、nctions here. / DONOT EDIT what you see in these blocks of generated code !/AFX_MSGDECLARE_MESSAGE_MAP();/AFX_INSERT_LOCATION / Microsoft Visual C+ will insert additional declarations immediately before the previous line.#endif/ !defined(AFX_CHATROOMSERVER_H_680EC642_E19B _4D55_88DF_2C9E9B1B30FD_INC

19、LUDED_)/ChatRoomServerDlg.h :header file /#if !defined(AFX_CHATROOMSERVERDLG_H 5BE648B6 _8A9C_4E90_BF1D_20FE943A525F INCLUDED_)#defineAFX_CHATROOMSERVERDLG_H 5BE648B6_8A9C_4E90_BF1D_20FE943A525F INCLUDED_#include“ ClientSocketList.hA dd/dby ClassView #include“ListenSocket.h " Added by ClassView

20、 #if _MSC_VER > 1000#pragma once #endif / _MSC_VER >1000/CChatRoomServerDlg dialog class CChatRoomServerDlg public CDialog / Construction public: CListenSocket ListenSocket; CChatRoomServerDlg(CWnd* pParent =NULL);/ standard constructor / Dialog Data /AFX_DATA(CChatRoomServerDlg) enum IDD =IDD

21、_CHATROOMSERVER_DIALOG;CButtonm_IDC_BUTTON_STOP;CButtonm_IDC_BUTTON_START; /AFX_DATA / ClassWizard generated virtual function overrides AFX_VIRTUAL(CChatRoomServerDlg) protected: virtual void DoDataExchange(CDataExchange* pDX);/ DDX/DDV support /AFX_VIRTUAL / Implementation protected: HICON m_hIcon;

22、 / Generated message map functions AFX_MSG(CChatRoomServerDlg)virtual BOOLOnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg void OnButtonStart(); afx_msg void OnButtonStop(); /AFX_MSG DECLARE_MESSAGE_MAP();/AFX_INSE

23、RT_LOCATION / Microsoft Visual C+ will insert additional declarations immediately before the previous line.#endif/ !defined(AFX_CHATROOMSERVERDLG_H 5BE648B6_ 8A9C_4E90_BF1D_20FE943A525F INCLUDED_) #if !defined(AFX_CLIENTSOCKET_H 5B707F31_3AD5_4F 47_B58E_ECFC99EB60F0_INCLUDED_)#defineAFX_CLIENTSOCKET

24、_H 5B707F31_3AD5_4F47_B58E_ECFC99EB60F0_INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif / _MSC_VER > 1000 / ClientSocket.h : headerfile/CClientSocket command target class CClientSocketList; class CClientSocket : public CSocket / Attributes public: / Operations public: CClientSocket(CClientSo

25、cketList *); virtual CClientSocket。; Overrides public: CClientSocketList *List; CClientSocket * Front; CClientSocket * Next; / ClassWizard generatedvirtualfunctionoverridesAFX_VIRTUAL(CClientSocket)public: virtual voidOnReceive(int nErrorCode); virtual void OnClose(int nErrorCode); /AFX_VIRTUAL / Ge

26、nerated message map functions /AFX_MSG(CClientSocket) / NOTE - the ClassWizard will add and remove member functions here. /AFX_MSG / Implementation protected:;/ /AFX_INSERT_LOCATION / Microsoft Visual C+ will insert additional declarations immediately before the previous line.#endif !defined(AFX_CLI

27、ENTSOCKET_H 5B707F31_3AD5_4F4 7_B58E_ECFC99EB60F0 INCLUDED_)/ ClientSocketList.h: interface for the CClientSocketList class. / /#if !defined(AFX_CLIENTSOCKETLIST_H_E746355D_FA1 0_4D12_B544_2FF152C16414 INCLUDED_)#defineAFX_CLIENTSOCKETLIST_H_E746355D_FA10_4D12_B544_2FF152C16414 INCLUDED_#include“ Cl

28、ientSocket.h “ #if _MSC_VER > 1000 #pragma once #endif/ _MSC_VER > 1000 class CClientSocketList public: BOOL Sends(CClientSocket *); BOOL Add(CClientSocket *); CClientSocket * Head; CClientSocketList(); virtual CClientSocketList。;;#endif/ !defined(AFX_CLIENTSOCKETLIST_H_E746355D_FA10 _4D12_B54

29、4_2FF152C16414 INCLUDED_)#if !defined(AFX_LISTENSOCKET_H 5D655304_370E_468 0_A556_E417552D24EC INCLUDED_)#defineAFX_LISTENSOCKET_H 5D655304_370E_4680_A556_E4 17552D24EC INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif / _MSC_VER > 1000 / ListenSocket.h : header file/#include“ ClientSocketList

30、.h “ / / CListenSocket command target classCListenSocket : public CSocket / Attributes public: /Operations public: CClientSocketList CCSL;/ 客戶 socket 列表 CListenSocket(); virtual CListenSocket(); / Overrides public: / ClassWizard generatedvirtualfunctionoverridesAFX_VIRTUAL(CListenSocket)public: virt

31、ual voidOnAccept(int nErrorCode);/ 重載OnAccept 函數/AFX_VIRTUAL / Generated message map functions AFX_MSG(CListenSocket) / NOTE - the ClassWizard will add and remove member functions here. /AFX_MSG / Implementationprotected:;/ /AFX_INSERT_LOCATION / Microsoft Visual C+ will insert additional declaratio

32、ns immediately before the previous line.#endif !defined(AFX_LISTENSOCKET_H 5D655304_370E_4680 _A556_E417552D24EC_INCLUDED_)/ChatRoomServer.cpp : Defines the class behaviors for the application. / #include “stdafx.h “ #include“ ChatRoomServer.h #include “ ChatRoomServerDlg.h #ifdef _DEBUG #define new

33、 DEBUG_NEW #undef THIS_FILE static char THIS_FILE口= FILE; #endif/CChatRoomServerAppBEGIN_MESSAGE_MAP(CChatRoomServerApp, CWinApp) /AFX_MSG_MAP(CChatRoomServerApp) / NOTE - the ClassWizard will add and remove mapping macros here. / DO NOT EDIT what you see in these blocks of generated code! /AFX_MSGO

34、N_COMMAND(ID_HELP,CWinApp:OnHelp)END_MESSAGE_MAP()/CChatRoomServerAppconstructionCChatRoomServerApp:CChatRoomServerApp() / TODO: add construction code here, / Place all significant initialization inInitInstance/ / The one and only CChatRoomServerApp object CChatRoomServerApp theApp; /CChatRoomServer

35、AppinitializationBOOLCChatRoomServerApp:InitInstance() if (!AfxSocketInit() AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; AfxEnableControlContainer(); /Standardinitialization / If you are not using these features and wish to reduce the size / of your final executable, you should remove from the following / the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls();/ Call thi

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論