├── Server.h
├── main.cpp
├── Server.cpp
├── Session.cpp
├── Session.h
├── DataBuffer.h
├── DataBuffer.cpp
├── TestClient
├── Session.h
├── main.cpp
├── DataBuffer.h
├── Session.cpp
├── 协议简单示例.xlsx
├── DataBuffer.cpp
├── IOServicePool.h
├── TestClient.vcxproj.filters
├── IOServicePool.cpp
└── TestClient.vcxproj
├── README.md
├── GameServer.vcxproj.user
├── .gitattributes
├── .gitignore
├── GameLog.h
├── IOServicePool.h
├── IOServicePool.cpp
├── GameServer.vcxproj.filters
├── ClassDiagram.cd
└── GameServer.vcxproj
/Server.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/Server.h
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/main.cpp
--------------------------------------------------------------------------------
/Server.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/Server.cpp
--------------------------------------------------------------------------------
/Session.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/Session.cpp
--------------------------------------------------------------------------------
/Session.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/Session.h
--------------------------------------------------------------------------------
/DataBuffer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/DataBuffer.h
--------------------------------------------------------------------------------
/DataBuffer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/DataBuffer.cpp
--------------------------------------------------------------------------------
/TestClient/Session.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/TestClient/Session.h
--------------------------------------------------------------------------------
/TestClient/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/TestClient/main.cpp
--------------------------------------------------------------------------------
/TestClient/DataBuffer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/TestClient/DataBuffer.h
--------------------------------------------------------------------------------
/TestClient/Session.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/TestClient/Session.cpp
--------------------------------------------------------------------------------
/TestClient/协议简单示例.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/TestClient/协议简单示例.xlsx
--------------------------------------------------------------------------------
/TestClient/DataBuffer.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnlanni/GameServer/HEAD/TestClient/DataBuffer.cpp
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GameServer
2 | 基于boost.asio实现,分room异步收发TCP;内含一个测试用客户端程序
3 | #类关系图
4 | 
5 |
--------------------------------------------------------------------------------
/GameServer.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # =========================
18 | # Operating System Files
19 | # =========================
20 |
21 | # OSX
22 | # =========================
23 |
24 | .DS_Store
25 | .AppleDouble
26 | .LSOverride
27 |
28 | # Icon must end with two \r
29 | Icon
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear on external disk
35 | .Spotlight-V100
36 | .Trashes
37 |
38 | # Directories potentially created on remote AFP share
39 | .AppleDB
40 | .AppleDesktop
41 | Network Trash Folder
42 | Temporary Items
43 | .apdisk
44 |
--------------------------------------------------------------------------------
/GameLog.h:
--------------------------------------------------------------------------------
1 | #ifndef GAMELOG_INCLUDE_H
2 | #define GAMELOG_INCLUDE_H
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #endif
--------------------------------------------------------------------------------
/IOServicePool.h:
--------------------------------------------------------------------------------
1 | #ifndef _IO_SERVICE_POOL_H_
2 | #define _IO_SERVICE_POOL_H_
3 | #include
4 | #include
5 | #include
6 | #include
7 | class IOServicePool
8 | : private boost::noncopyable
9 | {
10 | public:
11 | /// Construct the io_service pool.
12 | explicit IOServicePool(std::size_t poolsize);
13 |
14 | /// Run all io_service objects in the pool.
15 | void run();
16 |
17 | /// Stop all io_service objects in the pool.
18 | void stop();
19 |
20 | /// Get an io_service to use.
21 | boost::asio::io_service& get_io_service();
22 |
23 | private:
24 | typedef std::shared_ptr io_service_ptr;
25 | typedef std::shared_ptr work_ptr;
26 |
27 | /// The pool of io_services.
28 | std::vector io_services_;
29 |
30 | /// The work that keeps the io_services running.
31 | std::vector work_;
32 |
33 | /// The next io_service to use for a connection.
34 | std::size_t next_io_service_;
35 | };
36 | #endif
--------------------------------------------------------------------------------
/TestClient/IOServicePool.h:
--------------------------------------------------------------------------------
1 | #ifndef _IO_SERVICE_POOL_H_
2 | #define _IO_SERVICE_POOL_H_
3 | #include
4 | #include
5 | #include
6 | #include
7 | class IOServicePool
8 | : private boost::noncopyable
9 | {
10 | public:
11 | /// Construct the io_service pool.
12 | explicit IOServicePool(std::size_t poolsize);
13 |
14 | /// Run all io_service objects in the pool.
15 | void run();
16 |
17 | /// Stop all io_service objects in the pool.
18 | void stop();
19 |
20 | /// Get an io_service to use.
21 | boost::asio::io_service& get_io_service();
22 |
23 | private:
24 | typedef std::shared_ptr io_service_ptr;
25 | typedef std::shared_ptr work_ptr;
26 |
27 | /// The pool of io_services.
28 | std::vector io_services_;
29 |
30 | /// The work that keeps the io_services running.
31 | std::vector work_;
32 |
33 | /// The next io_service to use for a connection.
34 | std::size_t next_io_service_;
35 | };
36 | #endif
--------------------------------------------------------------------------------
/TestClient/TestClient.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | 源文件
20 |
21 |
22 | 源文件
23 |
24 |
25 | 源文件
26 |
27 |
28 | 源文件
29 |
30 |
31 |
32 |
33 | 头文件
34 |
35 |
36 | 头文件
37 |
38 |
39 | 头文件
40 |
41 |
42 |
--------------------------------------------------------------------------------
/IOServicePool.cpp:
--------------------------------------------------------------------------------
1 | #include "IOServicePool.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | IOServicePool::IOServicePool(std::size_t poolsize)
8 | : next_io_service_(0) {
9 | if (poolsize == 0)
10 | throw std::runtime_error("io_service_pool size is 0");
11 |
12 | // Give all the io_services work to do so that their run() functions will not
13 | // exit until they are explicitly stopped.
14 | for (std::size_t i = 0; i < poolsize; ++i) {
15 | io_service_ptr io_service(new boost::asio::io_service);
16 | work_ptr work(new boost::asio::io_service::work(*io_service));
17 | io_services_.push_back(io_service);
18 | work_.push_back(work);
19 | }
20 | }
21 |
22 | void IOServicePool::run() {
23 | // Create a pool of threads to run all of the io_services.
24 | std::vector > threads;
25 | for (std::size_t i = 0; i < io_services_.size(); ++i) {
26 | boost::shared_ptr thread(new std::thread(
27 | boost::bind(&boost::asio::io_service::run, io_services_[i])));
28 | threads.push_back(thread);
29 | }
30 |
31 | // Wait for all threads in the pool to exit.
32 | for (std::size_t i = 0; i < threads.size(); ++i)
33 | threads[i]->join();
34 | }
35 |
36 | void IOServicePool::stop() {
37 | // Explicitly stop all io_services.
38 | for (std::size_t i = 0; i < io_services_.size(); ++i)
39 | io_services_[i]->stop();
40 | }
41 |
42 | boost::asio::io_service& IOServicePool::get_io_service() {
43 | // Use a round-robin scheme to choose the next io_service to use.
44 | boost::asio::io_service& io_service = *io_services_[next_io_service_];
45 | ++next_io_service_;
46 | if (next_io_service_ == io_services_.size())
47 | next_io_service_ = 0;
48 | return io_service;
49 | }
--------------------------------------------------------------------------------
/TestClient/IOServicePool.cpp:
--------------------------------------------------------------------------------
1 | #include "IOServicePool.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | IOServicePool::IOServicePool(std::size_t poolsize)
8 | : next_io_service_(0) {
9 | if (poolsize == 0)
10 | throw std::runtime_error("io_service_pool size is 0");
11 |
12 | // Give all the io_services work to do so that their run() functions will not
13 | // exit until they are explicitly stopped.
14 | for (std::size_t i = 0; i < poolsize; ++i) {
15 | io_service_ptr io_service(new boost::asio::io_service);
16 | work_ptr work(new boost::asio::io_service::work(*io_service));
17 | io_services_.push_back(io_service);
18 | work_.push_back(work);
19 | }
20 | }
21 |
22 | void IOServicePool::run() {
23 | // Create a pool of threads to run all of the io_services.
24 | std::vector > threads;
25 | for (std::size_t i = 0; i < io_services_.size(); ++i) {
26 | boost::shared_ptr thread(new std::thread(
27 | boost::bind(&boost::asio::io_service::run, io_services_[i])));
28 | threads.push_back(thread);
29 | }
30 |
31 | // Wait for all threads in the pool to exit.
32 | for (std::size_t i = 0; i < threads.size(); ++i)
33 | threads[i]->join();
34 | }
35 |
36 | void IOServicePool::stop() {
37 | // Explicitly stop all io_services.
38 | for (std::size_t i = 0; i < io_services_.size(); ++i)
39 | io_services_[i]->stop();
40 | }
41 |
42 | boost::asio::io_service& IOServicePool::get_io_service() {
43 | // Use a round-robin scheme to choose the next io_service to use.
44 | boost::asio::io_service& io_service = *io_services_[next_io_service_];
45 | ++next_io_service_;
46 | if (next_io_service_ == io_services_.size())
47 | next_io_service_ = 0;
48 | return io_service;
49 | }
--------------------------------------------------------------------------------
/GameServer.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | 源文件
20 |
21 |
22 | 源文件
23 |
24 |
25 | 源文件
26 |
27 |
28 | 源文件
29 |
30 |
31 | 源文件
32 |
33 |
34 |
35 |
36 | 头文件
37 |
38 |
39 | 头文件
40 |
41 |
42 | 头文件
43 |
44 |
45 | 头文件
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/ClassDiagram.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | DataBuffer.h
9 |
10 |
11 |
12 |
13 | DataBuffer.h
14 |
15 |
16 |
17 |
18 | DataBuffer.h
19 |
20 |
21 |
22 |
23 | DataBuffer.h
24 |
25 |
26 |
27 |
28 | AAIAAAAIDAQEAAAAAAAAAAAAAAAAATAAAAAAAAAAABA=
29 | DataBuffer.h
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | IOServicePool.h
38 |
39 |
40 |
41 |
42 | IOServicePool.h
43 |
44 |
45 |
46 |
47 | AAAAAgAAAAAACAAAAAAAAQAAAAAhAAAAAQAAAAAAAEA=
48 | IOServicePool.h
49 |
50 |
51 |
52 |
53 |
54 | AAAAAAAAACAAQAAAAAAARAAEQAAAAAAACAAAAiAAEAE=
55 | Server.h
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | Session.h
64 |
65 |
66 |
67 |
68 | Session.h
69 |
70 |
71 |
72 |
73 | AAAAAggBgkAAIQIAAAgAQAYgEgCDhAAAAAEEAAHAYAI=
74 | Session.h
75 |
76 |
77 |
78 |
79 |
80 | AAgAEEAAAAAAAAAAALIAAAAAAAAAAAAAAAAACAAAQAA=
81 | Server.h
82 |
83 |
84 |
85 |
86 |
87 | AAAAAAAAAAAAAoAgACACAAAAAAAYAAIAAIAAAAAEAIA=
88 | DataBuffer.h
89 |
90 |
91 |
92 |
93 |
94 | AAsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
95 | DataBuffer.h
96 |
97 |
98 |
99 |
100 |
101 | AAAAAAAAAAAAAAAAAAAAAAAAAA4AAAAAAAAAAAAAAAA=
102 | DataBuffer.h
103 |
104 |
105 |
106 |
107 |
108 | AAAAAAAAAAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
109 | DataBuffer.h
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/GameServer.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {022B02FD-E5FA-4DC0-9B03-D29E90F98996}
15 | GameServer
16 |
17 |
18 |
19 | Application
20 | true
21 | v110
22 | MultiByte
23 |
24 |
25 | Application
26 | false
27 | v110
28 | true
29 | MultiByte
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | Level3
45 | Disabled
46 | true
47 | D:\boost_1_57_0\boost_1_57_0\;%(AdditionalIncludeDirectories)
48 | true
49 |
50 |
51 | true
52 | D:\boost_1_57_0\boost_1_57_0\lib;%(AdditionalLibraryDirectories)
53 | libboost_thread-vc110-mt-gd-1_57.lib;libboost_system-vc110-mt-gd-1_57.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
54 |
55 |
56 | true
57 |
58 |
59 |
60 |
61 | Level3
62 | MaxSpeed
63 | true
64 | true
65 | true
66 |
67 |
68 | true
69 | true
70 | true
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/TestClient/TestClient.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {8706F982-B757-480E-A3F0-9DF55B8EEC76}
15 | Win32Proj
16 | TestClient
17 |
18 |
19 |
20 | Application
21 | true
22 | v110
23 | Unicode
24 |
25 |
26 | Application
27 | false
28 | v110
29 | true
30 | Unicode
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | true
44 |
45 |
46 | false
47 |
48 |
49 |
50 |
51 |
52 | Level3
53 | Disabled
54 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
55 | true
56 | D:\boost_1_57_0\boost_1_57_0\;%(AdditionalIncludeDirectories)
57 |
58 |
59 | Console
60 | true
61 | D:\boost_1_57_0\boost_1_57_0\lib;%(AdditionalLibraryDirectories)
62 | libboost_date_time-vc110-mt-gd-1_57.lib;libboost_thread-vc110-mt-gd-1_57.lib;libboost_system-vc110-mt-gd-1_57.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
63 |
64 |
65 |
66 |
67 | Level3
68 |
69 |
70 | MaxSpeed
71 | true
72 | true
73 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
74 | true
75 |
76 |
77 | Console
78 | true
79 | true
80 | true
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------