【正文】
在課程設計過程中,收獲知識,提高能力的同時,我也學到了很多人生的哲理,懂得怎么樣去制定計劃,怎么樣去實現這個計劃,并掌握了在執(zhí)行過程中怎么樣去克服心理上的不良情緒。通過上網查詢收集資料和同學的交流,讓我覺得要完成一個任務,一個人悄無聲息是很難做好的,和同學交流研究會使我們獲得更多,也能使自己少走許多彎路,這樣才能事半功倍。要想學好網絡編程要重在實踐,必須通過不斷的實踐操作才能更好地掌握它。八、課程設計的評價、收獲與建議本次課程設計符合設計要求,內容比較詳細,能夠實現網絡文字聊天程序的基本功能,但開發(fā)的程序也有一定的局限性:(1)未能實現服務器端和客戶端互通消息;(2)只能在局域網中進行聊天,若客戶端跟服務器得IP地址不一樣,即使輸入服務器的名稱正確,也不能連上服務器;(3)客戶端之間不能進行私聊,只能在類似的聊天室里聊天;(4)聊天信息不能保存,退出后用同一昵稱登錄看不到之前的聊天信息;(5)聊天信息沒有時間顯示。“監(jiān)聽”按鈕若沒有被點擊,客戶端即使輸入正確的服務器名稱,點擊“連接”時也會提示“連接服務器失??!”;在用客戶端聊天時,最好使用不少于兩個客戶端,方便驗證實驗結果。}七、運行結果及其分析(一)運行結果圖3 服務器端初始化界面圖4 客戶端初始化界面圖5 輸入服務器名稱和昵稱圖6 服務器沒監(jiān)聽情況下連接圖7 輸入錯誤的服務器名稱圖8 服務器監(jiān)聽情況下連接圖9 新客戶使用客戶端圖10 服務器通知新用戶進入圖11 客戶端之間互通消息(二)分析整個程序實現了網絡文字聊天的基本功能,主要代碼分放在Server和Client兩個文件夾中,也可以通過選擇用Visual C++ ,然后再編譯、運行程序。 (%s%s,m_name,進入聊天室)。 return。 port = 70。 CString servername = m_servername。 //將數據添加到列表框中 ((),str)。 (%s,buffer)。\039。 //接收傳來的數據 int factdata = pMysocketReceive(buffer,200)。 ()。 int num = pMysocketSend((()),())。 if (()|()) return。}void CClientDlg::OnButtonsend() { // TODO: Add your control notification handler code here CString str,temp。 } else { CDialog::OnPaint()。 int y = (() cyIcon + 1) / 2。rect)。 CRect rect。 // 圖片居中顯示 int cxIcon = GetSystemMetrics(SM_CXICON)。 }}// If you add 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 CClientDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this)。 ()。 // return TRUE unless you set the focus to a control}void CClientDlg::OnSysCommand(UINT nID, LPARAM lParam){ if ((nID amp。 return false。 //創(chuàng)建套接字對象 if (!pMysocketCreate()) //創(chuàng)建套接字 { delete pMysocket。 // 設置大圖 SetIcon(m_hIcon, FALSE)。 } } // Set the icon for this dialog. The framework does this automatically // when the application39。 if (!()) { pSysMenuAppendMenu(MF_SEPARATOR)。 if (pSysMenu != NULL) { CString strAboutMenu。 ASSERT(IDM_ABOUTBOX 0xF000)。 // Add About... menu item to system menu. // IDM_ABOUTBOX must be in the system mand range. ASSERT((IDM_ABOUTBOX amp。 DDX_Text(pDX, IDC_EDIT3, m_servername)。 DDX_Control(pDX, IDC_EDIT2, m_info)。}void CClientDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX)。 m_servername = _T()。CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD){ //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT}void CAboutDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX)。 //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg)protected: virtual void DoDataExchange(CDataExchange* pDX)。endif/////////////////////////////////////////////////////////////////////////////// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog{public: CAboutDlg()。 if (socket != NULL) socketSend(bufferdata,result)。 POSITION pos = ()。 //接收客戶端傳來的數據 int result = socketReceive(bufferdata,BUFFERSIZE)。 else delete socket。}void CServerDlg::AcceptConnect(){