MySock 应用Socket编程实现一个简单的网络聊天程序。VC++


应用Socket编程实现一个简单的网络聊天程序。聊天框架由客户端和服务器端组成,服务器连接、消息接收以及关闭等功能。是通过建立基于对话框的MFC工程文件来实现编程,并支持window socket。重点在于整体的设计是基于对话框和类的。 先进行对话框的布局以及各个控件属性的设置,再为控件添加响应函数和成员变量。客户端和服务器端整合到一个对话框,利用设置radio button可以对两者进行切换,并写入相应的程序代码。客户端对应“连接”按钮,服务器端对应“监听”按钮。为其添加socket类和相应的代码。添加类相应的各代码后,进行客户端和服务器端的连接。编译启动时,启动两份,分别选择客户端和服务器端就可以进行对话了。
资源截图
代码片段和文件信息
// MySock.cpp : Defines the class behaviors for the application.
//

#include “stdafx.h“
#include “MySock.h“
#include “MySockDlg.h“

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

/////////////////////////////////////////////////////////////////////////////
// CMySockApp

BEGIN_MESSAGE_MAP(CMySockApp CWinApp)
//{{AFX_MSG_MAP(CMySockApp)
// 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()

/////////////////////////////////////////////////////////////////////////////
// CMySockApp construction

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

/////////////////////////////////////////////////////////////////////////////
// The one and only CMySockApp object

CMySockApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CMySockApp initialization

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

AfxEnableControlContainer();

// 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

CMySockDlg 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;
}

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

     文件     114768  2011-07-07 14:54  MySockDebugMySock.exe

     文件     229648  2011-07-07 14:54  MySockDebugMySock.ilk

     文件      15270  2010-05-17 23:10  MySockDebugMySock.obj

     文件    5705916  2010-05-17 23:10  MySockDebugMySock.pch

     文件     402432  2011-07-07 14:54  MySockDebugMySock.pdb

     文件       3096  2011-07-07 14:54  MySockDebugMySock.res

     文件       9347  2010-05-17 23:10  MySockDebugMySocket.obj

     文件     106508  2010-05-17 23:10  MySockDebugStdAfx.obj

     文件     353280  2011-11-09 18:14  MySockDebugvc60.idb

     文件     372736  2011-07-06 16:03  MySockDebugvc60.pdb

     文件      36935  2011-07-06 16:03  MySockDebugMySockDlg.obj

     文件       1851  2011-11-09 17:55  MySockMySock.clw

     文件       2157  2009-05-30 21:51  MySockMySock.cpp

     文件       4287  2009-05-31 01:22  MySockMySock.dsp

     文件        535  2009-05-30 21:51  MySockMySock.dsw

     文件       1324  2009-05-30 21:51  MySockMySock.h

     文件     107520  2011-11-09 18:14  MySockMySock.ncb

     文件        727  2011-07-07 14:54  MySockMySock.plg

     文件       1726  2009-05-31 00:51  MySockMySockDlg.h

     文件       2183  2009-05-31 00:03  MySockMySocket.cpp

     文件       1447  2009-05-31 00:03  MySockMySocket.h

     文件       3579  2009-05-30 21:51  MySockReadMe.txt

     文件       1078  2009-05-30 21:51  MySock
esMySock.ico

     文件        398  2009-05-30 21:51  MySock
esMySock.rc2

    ..A.SH.      6144  2012-03-14 10:44  MySock
esThumbs.db

     文件       1373  2009-05-31 01:15  MySock
esource.h

     文件        208  2009-05-30 21:51  MySockStdAfx.cpp

     文件       1102  2009-05-30 21:51  MySockStdAfx.h

     文件      12130  2011-07-06 15:56  MySockRCa03588

     文件       8297  2011-07-06 16:03  MySockMySockDlg.cpp

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)