Swa-server Open Source Framework
* Suitable for small and medium-sized games, such as: Nurturance, RPG, chess, etc. application software, such as: chat room, etc.
* Already envelopes good bottom socket management, SQL request processing, data encryption and decryption
* Get started writing business
* Swa-server is a framework for small and fast development, so the use of single-process mode, the next update is a single-process solution to solve the problems encountered, so as to reduce development time and manpower (in fact, many servers with a single process is enough)
* Support IO Async (based on boost library IO)
* Supports SQL asynchronous execution (with callback function)
* Player Manager
* Database Manager
Examples of projects
* 1, Request for dynamic password
* 2, request login (including MySQL query processing return, etc.)
installation process
* 1, install a vs2012
* 2, download the Code of this project
* 3, download third-party library (boost and MySQL), MySQL has been compiled good address: Http://pan.baidu.com/s/1qW7b42S,boost version is too large, self-download to the official website, version 1.55
* 4, install the MySQL database, and import the project's SQL file
* 5. Compile and run, use client test in Project
Structure diagram:
Shared for a static share of the library, the library mainly includes socket management, database management
Run diagram
Server startup process (code below):
int main (int argc, const char * argv[]) {//Initialize the server to be ready for data Init ();//Start service ServerStart ();//Perform exit related operation Runserverexit (); retur n 0;} void Init () {//Initialize protocol initnetmsg ();//load Config g_rgamecfg.loadres (".. /conf/gameconfig.xml ");//server-related configuration const gameconfiginfo& Rgamecfginfo = G_rgamecfg.getgameconfiginfo ();// Load the resource required by the server g_rresourcemgr.loadallres (Rgamecfginfo.arrconfigpath);//Initialize database if (Dbserverinit (Rgamecfginfo)) {// Initialize the Scoket service gnetserver = Netservermgr::instance ()->addnetserver (); Gnetserver->setaddress ( Rgamecfginfo.arrserverhost, Rgamecfginfo.nserverport); Gnetserver->sethandler (OnNetMsgEnter, ONNETMSG, ONNETMSGEXIT);//Initialize the player data to be connected G_rplayermgr.init (*gnetserver);//Start Socket service Gnetserver->start (); FLOG4 ("SERVER STARTED."); /auxiliary Command initialization ggamecommand.init ();}}
Start the process to do all the initialization work, load the configuration, create all sockets, player, database objects, etc., and then set the socket connection, receive the message, exit the callback function
The socket here is the same as the player's instance ID, and they are also tied together to manage it, so it's convenient
When a socket comes in, it can go directly to the player, and when a socket exits, it initializes the player and socket data, and then sets them to wait for the connection to enter again.
Main code in Netsocket,netserver,playaer
Netsocket
Netserver::netserver (): m_cacceptor (*this) {static Int32 S_nincreasenetserverid = 0;m_nserverid = ++s_ nincreasenetserverid;for (int i = 0; i < Max_socket_connect; i++) {m_arrsocket[i] = new Netsocket (*this);}}
Player
void Playermgr::init (netserver& rnetserver) {for (Int32 i = 0; i < max_socket_connect; i++) {swa::netsocket& Psocket = Rnetserver.getsocket (i); ASSERT (psocket.sid () = = i); M_arrplayercache[i] = new Player (Psocket);}}
If the garden friends want to use directly, just look at the example code to get started, if you want to study, then see the Netsocket,netserver,netiobuffer class in GKFX
If you have any questions, you can ask questions here, or contact me qq:296464231
The source has been put into the Github:https://github.com/huangzuduan/swa-server
Share the C++socket framework swa-server (open source + source) that has been maintaining a simple and practical and efficient