資源簡介
最新的C C++Socket技術總結!
開發環境:VS2010
實現功能:
1、運用多線程和Socket技術實現Socket Server端偵聽多個客戶端請求;
2、實現服務器端循環處理客戶端不同請求從而實現不同測試要求,并向客戶端循環發送數據;
3、實現客戶端向服務器端發送不同測試命令,并接收服務器端發送的數據;
4、運用指針上下文實現不同線程的數據共享;
5、實現多個客戶端同時連接服務器端;
6、服務器端程序和客戶端程序可以運行在同一臺計算機,也可以運行在兩臺計算機。
測試方法:
1、打開ServerDemo.exe
2、打開ClientDemo.exe 并輸入127.0.0.1(同一臺計算機)或目標機IP地址(兩臺計算機)

代碼片段和文件信息
#include?“stdio.h“
#include?“TcpCtl.h“
#include?
using?namespace?std;
typedef?unsigned?char?u8;
int?main()
{
int?j?=?0;
char?ip;
char?ipaddr[20];
int?c?=?0;
printf(“please?enter?target?ip?addr?to?connect(eg:127.0.0.1):\n“);
cin>>ipaddr;
printf(“client:?%s??port=6000\n“?ipaddr);
TcpCtl?*tcp1?=?new?TcpCtl((char*)?ipaddr?“6000“);
u8?buffer[65];
u8?revbuffer[65];
while(c?!=?30)
{
printf(“\npress?cmd?to?start?simulation\n“);
printf(“cmd=1:?Test1\tcmd=2:?Test2\tcmd=3:Test3\n“);
printf(“cmd=20:?Stop\tcmd=30:?Exit\tcmd?+?data?=?65bytes\n“);
scanf(“%d“?&c);
buffer[0]?=?(u8)c;
for(int?i?=0?;?i?64;?i++)
buffer[i+1]?=?i;
tcp1->SendCommand((char*)buffer?65?(char*)revbuffer);
}
getchar();
tcp1->DisConnect();
tcp1->Close();
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4062??2014-08-06?22:48??C?Socket通信多線程實例VS2010\ClientDemo\ClientDemo.vcxproj
?????文件????????357??2014-08-16?12:59??C?Socket通信多線程實例VS2010\ClientDemo\ClientDemo.vcxproj.filters
?????文件????????222??2014-08-16?13:02??C?Socket通信多線程實例VS2010\ClientDemo\ClientDemo.vcxproj.user
?????文件???????1282??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\cl.command.1.tlog
?????文件??????34018??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\CL.read.1.tlog
?????文件????????838??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\CL.write.1.tlog
?????文件??????????2??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件??????????2??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件??????????2??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件??????????2??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件??????????2??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件??????????2??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件??????????2??2014-08-08?21:11??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件??????????2??2014-08-08?21:11??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件??????????2??2014-08-08?21:11??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件??????????2??2014-08-08?21:11??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件???????1590??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件???????3132??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件????????824??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\li
?????文件??????76638??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\main.obj
?????文件????????378??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\mt.command.1.tlog
?????文件????????306??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\mt.read.1.tlog
?????文件????????306??2014-08-09?14:57??C?Socket通信多線程實例VS2010\ClientDemo\Debug\mt.write.1.tlog
?????文件????????516??2014-08-09?14:55??C?Socket通信多線程實例VS2010\ClientDemo\Debug\rc.command.1.tlog
?????文件????????278??2014-08-09?14:55??C?Socket通信多線程實例VS2010\ClientDemo\Debug\rc.read.1.tlog
?????文件????????286??2014-08-09?14:55??C?Socket通信多線程實例VS2010\ClientDemo\Debug\rc.write.1.tlog
?????文件??????36071??2014-08-09?14:52??C?Socket通信多線程實例VS2010\ClientDemo\Debug\TcpCtl.obj
?????文件???????2056??2014-08-09?14:52??C?Socket通信多線程實例VS2010\ClientDemo\Debug\TcpDemo.Build.CppClean.log
?????文件????????406??2014-08-09?14:55??C?Socket通信多線程實例VS2010\ClientDemo\Debug\TcpDemo.exe.em
?????文件????????472??2014-08-09?14:55??C?Socket通信多線程實例VS2010\ClientDemo\Debug\TcpDemo.exe.em
............此處省略76個文件信息
- 上一篇:數據結構—圖書館管理系統C++編寫
- 下一篇:MFC實現點對點通信
評論
共有 條評論