-
大小: 4.4MB文件類(lèi)型: .zip金幣: 2下載: 0 次發(fā)布日期: 2023-08-10
- 語(yǔ)言: C/C++
- 標(biāo)簽: 聊天應(yīng)用??源代碼??C++實(shí)驗(yàn)??大學(xué)實(shí)驗(yàn)??
資源簡(jiǎn)介
這是利用C++實(shí)現(xiàn)的一個(gè)簡(jiǎn)單的聊天應(yīng)用,包括客戶(hù)端和服務(wù)器,代碼都是完整的在visual studio里頭跑過(guò)的,程序很適合大學(xué)里的C++實(shí)驗(yàn)或是計(jì)算機(jī)網(wǎng)絡(luò)實(shí)驗(yàn)。當(dāng)然,建議大家借鑒學(xué)習(xí)就好,直接用來(lái)應(yīng)付實(shí)驗(yàn)這是不太好的。

代碼片段和文件信息
//?Client.cpp?:?定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//Author:duanfeifei
#include?“stdafx.h“
SOCKET?ConnectSock(const?char?*?transport?const?char?*?server)
{
SOCKET?clientSock;
sockaddr_in?sin;
int?type;
sin.sin_family?=?AF_INET;
sin.sin_port?=?SERVER_PORT;
//memcpy(sin.sin_addr.s_addr?server?sizeof(server));
sin.sin_addr.s_addr?=?inet_addr(server);
if(strcmp(transport?“tcp“)?==?0)
{
type?=?SOCK_STREAM;
}
else
{
type?=?SOCK_DGRAM;
}
if((clientSock?=?socket(PF_INET?type?0))?==?INVALID_SOCKET)
{
cout<<“create?socket?failure!“< exit(1);
}
if(connect(clientSock?(sockaddr?*)&sin?sizeof(sin))?0)
{
cout<<“connect?with?server?fialure!“< exit(1);
}
return?clientSock;
}
int?main(void)
{
char?serverIP[MAX_MESSAGE];
SOCKET?clientSock?=?0;
cout<<“Input?server?IP:?“;
cin>>serverIP;
WSADATA?wsaData;
if(WSAStartup(MAKEWORD(2?2)?&wsaData)?!=?0)
{
cout<<“Init?window?socket?failure!“< }
clientSock?=?ConnectSock(“tcp“?serverIP);
MyClient?*?pMyClient?=?new?MyClient(clientSock);
pMyClient->StartChat();
if(WSACleanup()?==?SOCKET_ERROR)
{?
cout<<“Clean?up?failure!“< }
delete?pMyClient;
return?0;
}
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件?????????104??2018-07-11?18:58??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\注意事項(xiàng).txt
?????目錄???????????0??2008-12-29?18:42??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\
?????文件????13716480??2008-12-07?12:39??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Chat.ncb
?????文件????????1334??2008-12-01?21:46??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Chat.sln
?????文件???????33280??2008-12-07?12:39??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Chat.suo
?????文件???????11264??2008-11-29?12:38??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Chat.suo.old
?????目錄???????????0??2008-12-29?18:43??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\
?????文件????????1259??2008-12-07?12:35??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\Client.cpp
?????文件????????4748??2008-12-01?21:46??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\Client.vcproj
?????文件????????3938??2008-12-01?09:18??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\Client.vcproj.7.10.old
?????文件????????1403??2008-12-02?11:28??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\Client.vcproj.B03.buaa.user
?????文件????????1427??2008-12-07?12:39??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\Client.vcproj.MICROSOF-554BD1.lilu.user
?????文件????????7273??2008-12-07?12:27??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\MyClient.cpp
?????文件?????????631??2008-12-07?12:31??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\MyClient.h
?????文件?????????985??2008-12-01?09:11??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\ReadMe.txt
?????文件?????????210??2008-12-01?09:11??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\stdafx.cpp
?????文件?????????645??2008-12-07?12:35??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Client\stdafx.h
?????目錄???????????0??2008-12-29?18:43??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\
?????文件????????4069??2008-12-07?12:30??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\MyServer.cpp
?????文件?????????404??2008-12-07?12:30??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\MyServer.h
?????文件?????????985??2008-12-01?09:11??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\ReadMe.txt
?????文件????????2068??2008-12-07?12:30??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\Server.cpp
?????文件????????4748??2008-12-01?21:46??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\Server.vcproj
?????文件????????3938??2008-12-01?09:15??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\Server.vcproj.7.10.old
?????文件????????1403??2008-12-02?11:28??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\Server.vcproj.B03.buaa.user
?????文件????????1427??2008-12-07?12:39??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\Server.vcproj.MICROSOF-554BD1.lilu.user
?????文件?????????210??2008-12-01?09:15??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\stdafx.cpp
?????文件?????????764??2008-12-07?12:32??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\Server\stdafx.h
?????目錄???????????0??2018-07-11?18:54??C++實(shí)現(xiàn)簡(jiǎn)單聊天應(yīng)用\注意事項(xiàng)\
評(píng)論
共有 條評(píng)論