资源简介

里面包含聊天室的客户端和服务器端的源文件和一份完整的设计报告。 一、 系统概要 本系统能实现基于VC++的网络聊天室系统。有单独的客户端、服务器端。 服务器应用程序能够接受来自客户端的广播,然后向客户端发送本机的IP与服务端口,让客户端接入到服务器进行聊天,检测用户名是否合法(重复),服务器责接收来自客户端的聊天信息,并根据用户的需求发送给指定的人或所有人,能够给出上线下线提示。客户端能够发出连接请求,能编辑发送信息,可以指定发给单人或所有人,能显示聊天人数,上线下线用户等。 二、 通信规范的制定 服务请求规范: 服务器端: (1) 创建一个UDP的套接字,接受来自客户端的广播请求,当请求报文内容为“REQUEST FOR IP ADDRESS AND SERVERPORT”时,接受请求,给客户端发送本服务器TCP聊天室的端口号。 (2) 创建一个主要的TCP协议的套接字负责客户端TCP连接 ,处理它的连接请求事件。 (3)在主要的TCP连接协议的套接字里面再创建TCP套接字保存到动态数组里,在主要的套接字接受请求后 ,就用这些套接字和客户端发送和接受数据。 客户端: (1) 当用户按“连接”按钮时,创建UDP协议套接字,给本地计算机发广播,广播内容为“REQUEST FOR IP ADDRESS AND SERVERPORT”。 (2)当收到服务器端的回应,收到服务器发来的端口号后,关闭UDP连接。根据服务器的IP地址和端口号重新创建TCP连接。 故我思考:客户端一定要知道服务器的一个端口,我假设它知道服务器UDP服务的端口,通过发广播给服务器的UDP服务套接字,然后等待该套接字发回服务器TCP聊天室服务的端口号,IP地址用ReceiveForom也苛刻得到。 通信规范 通信规范的制定主要跟老师给出的差不多,并做了一小点增加: (增加验证用户名是否与聊天室已有用户重复,在服务器给客户端的消息中,增加标志0) ① TCP/IP数据通信 --- “聊天”消息传输格式 客户机 - 服务器 (1)传输“用户名” STX+1+用户名+ETX (2) 悄悄话 STX+2+用户名+”,”+内容+ETX (3) 对所有人说 STX+3+内容+ETX 服务器- 客户机 (0)请求用户名与在线用户名重复 //改进 STX+0+用户名+EXT (1)首次传输在线用户名 STX+1+用户名+ETX (2)传输新到用户名 STX+2+用户名+ETX (3)传输离线用户名 STX+3+用户名+ETX (4)传输聊天数据 STX+4+内容+ETX (注:STX为CHR(2),ETX 为CHR(3)) 三、 主要模块的设计分析 四、 系统运行效果 (要求有屏幕截图) 五、 心得与体会

资源截图

代码片段和文件信息

// ChatClient.cpp : Defines the class behaviors for the application.
//

#include “stdafx.h“
#include “ChatClient.h“
#include “ChatClientDlg.h“

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChatClientApp

BEGIN_MESSAGE_MAP(CChatClientApp CWinApp)
//{{AFX_MSG_MAP(CChatClientApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
//    DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP CWinApp::onhelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChatClientApp construction

CChatClientApp::CChatClientApp()
{
// TODO: add construction code here
// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CChatClientApp object

CChatClientApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CChatClientApp initialization

BOOL CChatClientApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}

// Standard initialization
// 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 this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

CChatClientDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
}

// Since the dialog has been closed return FALSE so that we exit the
//  application rather than start the application‘s message pump.
return FALSE;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     120176  2009-12-30 14:00  ChatClient\ChatClient.aps

     文件       1797  2009-12-30 15:01  ChatClient\ChatClient.clw

     文件       2180  2009-12-26 19:19  ChatClient\ChatClient.cpp

     文件       4570  2009-12-29 18:38  ChatClient\ChatClient.dsp

     文件        733  2009-12-30 04:32  ChatClient\ChatClient.dsw

     文件       1368  2009-12-26 19:19  ChatClient\ChatClient.h

     文件     123904  2009-12-30 15:01  ChatClient\ChatClient.ncb

     文件      56832  2009-12-30 15:01  ChatClient\ChatClient.opt

     文件        254  2009-12-30 11:54  ChatClient\ChatClient.plg

     文件       6041  2009-12-30 09:47  ChatClient\ChatClient.rc

     文件       4665  2009-12-30 11:02  ChatClient\ChatClientDlg.cpp

     文件       1771  2009-12-30 11:02  ChatClient\ChatClientDlg.h

     文件       6930  2009-12-30 11:45  ChatClient\ClientSocket.cpp

     文件       2304  2009-12-30 11:02  ChatClient\ClientSocket.h

     文件     323436  2009-12-30 11:50  ChatClient\Debug\ChatClient.ilk

     文件      13904  2009-12-30 11:22  ChatClient\Debug\ChatClient.obj

     文件    5567824  2009-12-26 20:30  ChatClient\Debug\ChatClient.pch

     文件     435200  2009-12-30 11:50  ChatClient\Debug\ChatClient.pdb

     文件     101252  2009-12-30 09:47  ChatClient\Debug\ChatClient.res

     文件      22750  2009-12-30 11:22  ChatClient\Debug\ChatClientDlg.obj

     文件      39612  2009-12-30 11:50  ChatClient\Debug\ClientSocket.obj

     文件     106378  2009-12-26 20:30  ChatClient\Debug\StdAfx.obj

     文件      12390  2009-12-30 11:50  ChatClient\Debug\UserNameDlg.obj

     文件     222208  2009-12-30 14:39  ChatClient\Debug\vc60.idb

     文件     372736  2009-12-30 11:50  ChatClient\Debug\vc60.pdb

     文件       3651  2009-12-26 19:19  ChatClient\ReadMe.txt

     文件      98654  2009-12-26 20:41  ChatClient\res\ChatClient.ico

     文件        402  2009-12-26 19:19  ChatClient\res\ChatClient.rc2

     文件        693  2009-12-26 20:41  ChatClient\res\Master.manifest

     文件       1053  2009-12-29 18:06  ChatClient\resource.h

............此处省略57个文件信息

评论

共有 条评论