資源簡介
1、一個簡單的網絡游戲服務器,socket框架,底層用的是boost跨平臺的框架
2、基本實現socket,thread等基本類型的封裝。
3、實現了一個簡單server,client。
4、簡單實現了登錄,client模擬發送聊天消息,服務器端實現了,消息的廣播等
5、本實例,是從之前的一個頁游項目中,自己精簡出來的。麻雀雖小五臟俱全,對于學習網游服務器絕對有幫助

代碼片段和文件信息
#include?“client.h“
#include?“World.h“
#include?“LTime.h“
#include?“LMsg.h“
#include?“LTool.h“
void?Client::Tick()
{
//檢測0-2秒,發送一次chat消息
long?cur?=??LUnixTime::GetUnixTimeInSec();
if(cur?-?_timer?>?_interval?&&?_sp)
{
LMsgC2SChat?chat;
char?tmp[128];
sprintf(tmp“hello?speaks?count=%d“++count);
chat.chatMsg?=?tmp;
_sp->Send(chat.GetSendBuff());
_timer?=?cur;
_interval?=?L_rand(02);
}
}
//////////////////////////////////////////////////////////////////////////
ClientServer::~ClientServer()
{
}
bool?ClientServer::Init()
{
LNet::Init(World::Instance().GetConnectIp()World::Instance().GetConnectPort());
return?true;
}
bool?ClientServer::Final()
{
return?true;
}
void?ClientServer::RecvMsgPack(LBuffPtr?pBuffLSocketPtr?sp)
{
/*
* 收到某個socket的消息
*/
int?msgId?=?0;
pBuff->Read(msgId);
LMsg*?msg?=?LMsgFactory::Instance().CreateMsg(msgId);
if(msg)
{
msg->sp?=?sp;
msg->Read(*pBuff);
World::Instance().Push(msg);
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1038??2014-12-05?09:44??Library\client\client.cpp
?????文件????????577??2014-12-05?09:34??Library\client\client.h
?????文件?????????18??2014-12-04?17:16??Library\client\client.ini
?????文件???????4812??2014-12-05?10:00??Library\client\client.vcxproj
?????文件???????1327??2014-12-05?09:46??Library\client\client.vcxproj.filters
?????文件????????143??2014-12-05?09:32??Library\client\client.vcxproj.user
?????文件????????231??2014-12-05?10:10??Library\client\main.cpp
?????文件???????2143??2014-12-05?09:51??Library\client\world.cpp
?????文件????????528??2014-12-04?15:13??Library\client\world.h
?????文件?????????51??2014-12-05?10:06??Library\Debug\client.ini
?????文件?????????29??2014-12-05?10:07??Library\Debug\server.ini
?????文件????????652??2014-12-03?16:34??Library\Library\Lba
?????文件???????3037??2014-12-03?15:15??Library\Library\LBuff.h
?????文件???????4668??2014-12-05?09:06??Library\Library\Library.vcxproj
?????文件???????2629??2014-12-05?09:03??Library\Library\Library.vcxproj.filters
?????文件????????143??2014-12-05?09:01??Library\Library\Library.vcxproj.user
?????文件???????1691??2014-12-03?16:51??Library\Library\LIni.cpp
?????文件????????509??2014-12-03?16:51??Library\Library\LIni.h
?????文件???????2040??2014-12-03?18:06??Library\Library\LLog.cpp
?????文件???????1270??2014-12-03?19:08??Library\Library\LLog.h
?????文件???????1548??2014-12-04?17:50??Library\Library\LMsg.cpp
?????文件???????2660??2014-12-04?17:49??Library\Library\LMsg.h
?????文件???????1623??2014-12-04?12:46??Library\Library\LNet.cpp
?????文件???????1604??2014-12-04?13:10??Library\Library\LNet.h
?????文件???????1100??2014-12-05?09:12??Library\Library\LRunnable.cpp
?????文件????????875??2014-12-05?09:17??Library\Library\LRunnable.h
?????文件????????421??2014-12-05?09:09??Library\Library\LSingleton.h
?????文件???????3493??2014-12-04?13:28??Library\Library\LSocket.cpp
?????文件???????2189??2014-12-04?13:11??Library\Library\LSocket.h
?????文件???????3032??2014-12-03?17:59??Library\Library\LTime.cpp
............此處省略30個文件信息
- 上一篇:金蝶K3用戶密碼查看
- 下一篇:基于導頻的信道估計mmse算法
評論
共有 條評論