一个服务器对多个客户端的MFC Socket编程示例

上传者: xiaoxia711 | 上传时间: 2019-12-21 22:02:13 | 文件大小: 3.44MB | 文件类型: rar
环境:Windows XP SP3、 VC++ 6.0、 Windows 2003 SDK 使用步骤: 1、下载解压之后,使用VC++ 6.0打开两个工程:一个是SocketServer和一个ClientSocket工程。 2、首先运行服务器端工程,选默认的端口1008 3、然后运行客户端工程,选默认的端口1008和默认的服务器地址 4、再运行多个客户端进程 5、如果一切正常,可以每个客户端的消息发送,我们可以在服务端和各个客户端同步看到消息 实现一个服务器对多个客户端的关键是,在服务端的使用集合CPtrList类用保存客户端的socket对象,思想与Java中的编程思想一样,只不过Java中会使用多线程技术,在Vector集合保存客户端的socket对象,而MFC框架提供了CSocket类,它是一个异步通信的类,所以看上去代码比较Java的多线程代码简单的实现了一个对多的即时通讯功能。另外,MFC提供了CSocketFile类和CArchive类与CSocket类实现了C++的网络通讯编程功能。 本示例注释非常详细,所有的辅助类都放一个util目录中,然后在工程中分了一个目录来管理这些辅助类,使用代码非常清晰。手动书写部分的代码是按Java的规范书写,当然其它代码由IDE生成的,所以是MS的风格,所以当你看代码时,只要是使用“骆驮命名法”的方法都是本人书写的功能性代码。 参看的思路:在服务端要从回调方法onAccept读起;而客户端代码主要从OnSendButton方法读起,即可理解整个代码的意思。 阅读对象:具有Java的Socket编程经验的人员,并且希望能够书写出比Java效率更高的即时通讯程序的人员

文件下载

资源详情

[{"title":"( 74 个子文件 3.44MB ) 一个服务器对多个客户端的MFC Socket编程示例","children":[{"title":"SocketServer","children":[{"title":"MyPort.h <span style='color:#111;'> 1.28KB </span>","children":null,"spread":false},{"title":"SocketServerDlg.h <span style='color:#111;'> 2.18KB </span>","children":null,"spread":false},{"title":"Release","children":[{"title":"SocketServer.pch <span style='color:#111;'> 5.49MB </span>","children":null,"spread":false},{"title":"StdAfx.obj <span style='color:#111;'> 810B </span>","children":null,"spread":false},{"title":"SocketServer.res <span style='color:#111;'> 3.12KB </span>","children":null,"spread":false},{"title":"Message.obj <span style='color:#111;'> 6.77KB </span>","children":null,"spread":false},{"title":"SocketServer.exe <span style='color:#111;'> 28.00KB </span>","children":null,"spread":false},{"title":"MyPort.obj <span style='color:#111;'> 11.14KB </span>","children":null,"spread":false},{"title":"SocketServerDlg.obj <span style='color:#111;'> 33.18KB </span>","children":null,"spread":false},{"title":"socketclient.obj <span style='color:#111;'> 8.79KB </span>","children":null,"spread":false},{"title":"vc60.idb <span style='color:#111;'> 57.00KB </span>","children":null,"spread":false},{"title":"SocketServer.obj <span style='color:#111;'> 10.39KB </span>","children":null,"spread":false},{"title":"socketlistener.obj <span style='color:#111;'> 5.79KB </span>","children":null,"spread":false}],"spread":false},{"title":"SocketServer.aps <span style='color:#111;'> 36.09KB </span>","children":null,"spread":false},{"title":"res","children":[{"title":"SocketServer.rc2 <span style='color:#111;'> 404B </span>","children":null,"spread":false},{"title":"SocketServer.ico <span style='color:#111;'> 1.05KB </span>","children":null,"spread":false}],"spread":true},{"title":"SocketServer.dsw <span style='color:#111;'> 549B </span>","children":null,"spread":false},{"title":"SocketServer.dsp <span style='color:#111;'> 4.71KB </span>","children":null,"spread":false},{"title":"SocketServer.opt <span style='color:#111;'> 60.50KB </span>","children":null,"spread":false},{"title":"SocketServerDlg.cpp <span style='color:#111;'> 10.42KB </span>","children":null,"spread":false},{"title":"StdAfx.cpp <span style='color:#111;'> 214B </span>","children":null,"spread":false},{"title":"SocketServer.cpp <span style='color:#111;'> 2.19KB </span>","children":null,"spread":false},{"title":"resource.h <span style='color:#111;'> 1.08KB </span>","children":null,"spread":false},{"title":"SocketServer.ncb <span style='color:#111;'> 81.00KB </span>","children":null,"spread":false},{"title":"SocketServer.rc <span style='color:#111;'> 6.39KB </span>","children":null,"spread":false},{"title":"StdAfx.h <span style='color:#111;'> 1.08KB </span>","children":null,"spread":false},{"title":"MyPort.cpp <span style='color:#111;'> 1.31KB </span>","children":null,"spread":false},{"title":"SocketServer.clw <span style='color:#111;'> 2.33KB </span>","children":null,"spread":false},{"title":"util","children":[{"title":"socketlistener.h <span style='color:#111;'> 1.73KB </span>","children":null,"spread":false},{"title":"Message.cpp <span style='color:#111;'> 1.12KB </span>","children":null,"spread":false},{"title":"socketclient.h <span style='color:#111;'> 1.99KB </span>","children":null,"spread":false},{"title":"socketlistener.cpp <span style='color:#111;'> 1.23KB </span>","children":null,"spread":false},{"title":"socketclient.cpp <span style='color:#111;'> 2.66KB </span>","children":null,"spread":false},{"title":"Message.h <span style='color:#111;'> 1.25KB </span>","children":null,"spread":false}],"spread":false},{"title":"SocketServer.plg <span style='color:#111;'> 2.29KB </span>","children":null,"spread":false},{"title":"SocketServer.h <span style='color:#111;'> 1.36KB </span>","children":null,"spread":false},{"title":"ReadMe.txt <span style='color:#111;'> 3.60KB </span>","children":null,"spread":false}],"spread":false},{"title":"ClientSocket","children":[{"title":"ClientSocketDlg.h <span style='color:#111;'> 1.82KB </span>","children":null,"spread":false},{"title":"ClientSocket.dsp <span style='color:#111;'> 4.56KB </span>","children":null,"spread":false},{"title":"res","children":[{"title":"ClientSocket.rc2 <span style='color:#111;'> 404B </span>","children":null,"spread":false},{"title":"ClientSocket.ico <span style='color:#111;'> 1.05KB </span>","children":null,"spread":false}],"spread":true},{"title":"ClientSocket.opt <span style='color:#111;'> 48.50KB </span>","children":null,"spread":false},{"title":"ClientSocket.dsw <span style='color:#111;'> 549B </span>","children":null,"spread":false},{"title":"ClientSocket.h <span style='color:#111;'> 1.36KB </span>","children":null,"spread":false},{"title":"ClientSocket.plg <span style='color:#111;'> 1.19KB </span>","children":null,"spread":false},{"title":"ClientSocket.rc <span style='color:#111;'> 6.50KB </span>","children":null,"spread":false},{"title":"ClientSocket.aps <span style='color:#111;'> 35.91KB </span>","children":null,"spread":false},{"title":"StdAfx.cpp <span style='color:#111;'> 214B </span>","children":null,"spread":false},{"title":"resource.h <span style='color:#111;'> 1.03KB </span>","children":null,"spread":false},{"title":"ClientSocket.ncb <span style='color:#111;'> 73.00KB </span>","children":null,"spread":false},{"title":"StdAfx.h <span style='color:#111;'> 1.08KB </span>","children":null,"spread":false},{"title":"util","children":[{"title":"Message.cpp <span style='color:#111;'> 1.14KB </span>","children":null,"spread":false},{"title":"ChatSocket.cpp <span style='color:#111;'> 1.09KB </span>","children":null,"spread":false},{"title":"Message.h <span style='color:#111;'> 1.25KB </span>","children":null,"spread":false},{"title":"chatsocket.h <span style='color:#111;'> 1.24KB </span>","children":null,"spread":false}],"spread":false},{"title":"Debug","children":[{"title":"ClientSocket.ilk <span style='color:#111;'> 283.72KB </span>","children":null,"spread":false},{"title":"ClientSocket.pch <span style='color:#111;'> 5.31MB </span>","children":null,"spread":false},{"title":"StdAfx.obj <span style='color:#111;'> 104.26KB </span>","children":null,"spread":false},{"title":"ClientSocket.exe <span style='color:#111;'> 116.09KB </span>","children":null,"spread":false},{"title":"Message.obj <span style='color:#111;'> 11.41KB </span>","children":null,"spread":false},{"title":"ChatSocket.obj <span style='color:#111;'> 7.17KB </span>","children":null,"spread":false},{"title":"ClientSocket.obj <span style='color:#111;'> 14.61KB </span>","children":null,"spread":false},{"title":"ClientSocket.pdb <span style='color:#111;'> 441.00KB </span>","children":null,"spread":false},{"title":"vc60.idb <span style='color:#111;'> 225.00KB </span>","children":null,"spread":false},{"title":"SetupDlg.obj <span style='color:#111;'> 14.73KB </span>","children":null,"spread":false},{"title":"vc60.pdb <span style='color:#111;'> 364.00KB </span>","children":null,"spread":false},{"title":"ClientSocketDlg.obj <span style='color:#111;'> 49.86KB </span>","children":null,"spread":false},{"title":"ClientSocket.res <span style='color:#111;'> 3.10KB </span>","children":null,"spread":false}],"spread":false},{"title":"ClientSocket.clw <span style='color:#111;'> 2.23KB </span>","children":null,"spread":false},{"title":"ClientSocketDlg.cpp <span style='color:#111;'> 8.87KB </span>","children":null,"spread":false},{"title":"SetupDlg.h <span style='color:#111;'> 1.23KB </span>","children":null,"spread":false},{"title":"ReadMe.txt <span style='color:#111;'> 3.60KB </span>","children":null,"spread":false},{"title":"SetupDlg.cpp <span style='color:#111;'> 1.45KB </span>","children":null,"spread":false},{"title":"ClientSocket.cpp <span style='color:#111;'> 2.19KB </span>","children":null,"spread":false}],"spread":false}],"spread":true}]

评论信息

  • liaochenggu :
    感谢分享,资源可以用。
    2018-11-28
  • d02540329 :
    感谢分享!不错学习了!效果不错啊!
    2018-11-19
  • asewq916 :
    好资源,感谢分享
    2018-07-14
  • mydaonet :
    谢谢楼主共享资源
    2018-05-11
  • fengshu168 :
    编写一个服务器程序。下来参考。
    2018-04-14

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明