資源簡介
我用MFC VC6編寫的一個(gè) TCP 一對(duì)多通信的程序,就是服務(wù)器端利用多線程技術(shù)(不使用Select等任何模型), 能同時(shí)接收多個(gè)客戶端的消息,
其次, 服務(wù)器端還能將消息群發(fā)給所有已連接的客戶端, 實(shí)現(xiàn)的基本思路 是將每個(gè)線程中 accept函數(shù)返回的套接字 都保存到一個(gè)套接字?jǐn)?shù)組中,套接字地址也保存到一個(gè)數(shù)組中。然后在“群發(fā)”的 按鈕消息中,用for循環(huán) 遍歷套接字?jǐn)?shù)組,循環(huán)執(zhí)行 send函數(shù)將消息發(fā)送給套接字?jǐn)?shù)組中所有的套接字。
該程序簡單完整,非常適合初學(xué)者研究WinSock一對(duì)多通信

代碼片段和文件信息
//?stdafx.cpp?:?source?file?that?includes?just?the?standard?includes
// TCPzcli.pch?will?be?the?pre-compiled?header
// stdafx.obj?will?contain?the?pre-compiled?type?information
#include?“stdafx.h“
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????35100??2019-01-28?21:19??Chat服務(wù)器端\Chat.aps
?????文件????????961??2019-01-31?16:22??Chat服務(wù)器端\Chat.clw
?????文件???????2129??2019-01-18?10:39??Chat服務(wù)器端\Chat.cpp
?????文件???????4123??2019-01-18?10:39??Chat服務(wù)器端\Chat.dsp
?????文件????????514??2019-01-18?10:39??Chat服務(wù)器端\Chat.dsw
?????文件???????1302??2019-01-18?10:39??Chat服務(wù)器端\Chat.h
?????文件??????58368??2019-01-31?16:22??Chat服務(wù)器端\Chat.ncb
?????文件??????54784??2019-01-31?16:22??Chat服務(wù)器端\Chat.opt
?????文件????????907??2019-01-31?11:56??Chat服務(wù)器端\Chat.plg
?????文件???????5074??2019-01-28?21:19??Chat服務(wù)器端\Chat.rc
?????文件???????6700??2019-01-31?11:55??Chat服務(wù)器端\ChatDlg.cpp
?????文件???????1793??2019-01-28?21:18??Chat服務(wù)器端\ChatDlg.h
?????文件???????5534??2019-01-28?10:31??Chat服務(wù)器端\chatdlg2.cpp
?????文件???????3543??2019-01-18?10:39??Chat服務(wù)器端\ReadMe.txt
?????文件???????1078??2019-01-18?10:39??Chat服務(wù)器端\res\Chat.ico
?????文件????????396??2019-01-18?10:39??Chat服務(wù)器端\res\Chat.rc2
?????文件????????819??2019-01-28?21:19??Chat服務(wù)器端\resource.h
?????文件????????206??2019-01-18?10:39??Chat服務(wù)器端\StdAfx.cpp
?????文件???????1102??2019-01-18?10:39??Chat服務(wù)器端\StdAfx.h
?????文件???????3597??2018-06-24?15:12??Chat客戶端\ReadMe.txt
?????文件???????1078??2018-06-24?15:12??Chat客戶端\res\TCPzcli.ico
?????文件????????399??2018-06-24?15:12??Chat客戶端\res\TCPzcli.rc2
?????文件????????915??2018-06-24?15:23??Chat客戶端\resource.h
?????文件????????209??2018-06-24?15:12??Chat客戶端\StdAfx.cpp
?????文件???????1054??2018-06-24?15:12??Chat客戶端\StdAfx.h
?????文件??????20936??2019-01-31?16:23??Chat客戶端\TCPzcli.aps
?????文件???????1345??2019-01-31?16:23??Chat客戶端\TCPzcli.clw
?????文件???????2077??2018-06-24?15:12??Chat客戶端\TCPzcli.cpp
?????文件???????4177??2018-06-24?15:12??Chat客戶端\TCPzcli.dsp
?????文件????????520??2018-06-24?15:12??Chat客戶端\TCPzcli.dsw
............此處省略14個(gè)文件信息
- 上一篇:掌紋識(shí)別c/c++代碼
- 下一篇:UE4C++游戲視頻教程
評(píng)論
共有 條評(píng)論