init:初始提交。
This commit is contained in:
commit
595a2c9761
17
.clang-format
Normal file
17
.clang-format
Normal file
@ -0,0 +1,17 @@
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
PointerAlignment: Left
|
||||
AccessModifierOffset: -4
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterFunction: true
|
||||
AfterClass: true
|
||||
Cpp11BracedListStyle: true
|
||||
ReflowComments: true
|
||||
SpacesBeforeTrailingComments: 3
|
||||
TabWidth: 4
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ColumnLimit: 80
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortEnumsOnASingleLine: false
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
build
|
||||
.vs
|
||||
.cache
|
||||
cmake-*
|
98
.vscode/settings.json
vendored
Normal file
98
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
{
|
||||
"files.autoSave": "onFocusChange",
|
||||
"editor.fontSize": 14,
|
||||
"editor.fontFamily": "'Source Code Pro', 'Source Code Pro', 'Source Code Pro'",
|
||||
"terminal.integrated.fontFamily": "Source Code Pro",
|
||||
"cmake.configureOnOpen": true,
|
||||
"cmake.debugConfig": {
|
||||
"console": "integratedTerminal",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "-gdb-set charset utf-8",
|
||||
"text": "-gdb-set charset UTF-8"
|
||||
},
|
||||
{
|
||||
"description": "Enable gdb pretty-printing",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
//"visualizerFile": "${workspaceRoot}/.vscode/qt6.natvis",
|
||||
"args": [
|
||||
]
|
||||
},
|
||||
"cmake.configureArgs": [
|
||||
"-Wno-dev",
|
||||
"-DCMAKE_PREFIX_PATH:STRING=C:/Dev/wxwidgets"
|
||||
],
|
||||
"cmake.options.statusBarVisibility": "visible",
|
||||
"cmake.generator": "Ninja",
|
||||
"C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json",
|
||||
"C_Cpp.default.cppStandard": "c++17",
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
||||
"editor.inlayHints.enabled": "off",
|
||||
"editor.unicodeHighlight.allowedLocales": {
|
||||
"ja": true,
|
||||
"zh-hant": true,
|
||||
"zh-hans": true
|
||||
},
|
||||
"files.associations": {
|
||||
"algorithm": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"cctype": "cpp",
|
||||
"charconv": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"exception": "cpp",
|
||||
"format": "cpp",
|
||||
"functional": "cpp",
|
||||
"hash_map": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"ios": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"iterator": "cpp",
|
||||
"limits": "cpp",
|
||||
"list": "cpp",
|
||||
"locale": "cpp",
|
||||
"memory": "cpp",
|
||||
"new": "cpp",
|
||||
"optional": "cpp",
|
||||
"ostream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"utility": "cpp",
|
||||
"vector": "cpp",
|
||||
"xfacet": "cpp",
|
||||
"xhash": "cpp",
|
||||
"xiosbase": "cpp",
|
||||
"xlocale": "cpp",
|
||||
"xlocbuf": "cpp",
|
||||
"xlocinfo": "cpp",
|
||||
"xlocmes": "cpp",
|
||||
"xlocmon": "cpp",
|
||||
"xlocnum": "cpp",
|
||||
"xloctime": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"xstring": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"xutility": "cpp"
|
||||
}
|
||||
}
|
19
CMakeLists.txt
Normal file
19
CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(gtransm LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if (MSVC)
|
||||
add_compile_options(/utf-8)
|
||||
endif()
|
||||
|
||||
set(CMAKE_DEBUG_POSTFIX "d")
|
||||
message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
|
||||
message(STATUS "Compiler CXX ID: ${CMAKE_CXX_COMPILER_ID}")
|
||||
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/)
|
||||
|
||||
add_subdirectory(server-core)
|
||||
add_subdirectory(example)
|
0
client-core/CMakeLists.txt
Normal file
0
client-core/CMakeLists.txt
Normal file
0
client-core/client-core.cxx
Normal file
0
client-core/client-core.cxx
Normal file
0
client-core/client-core.h
Normal file
0
client-core/client-core.h
Normal file
11
example/CMakeLists.txt
Normal file
11
example/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(example LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(wxWidgets CONFIG REQUIRED)
|
||||
|
||||
add_executable(server-core-use server-core-use.cxx)
|
||||
target_link_libraries(server-core-use PRIVATE server-core wx::net)
|
||||
set_target_properties(server-core-use PROPERTIES WIN32_EXECUTABLE TRUE)
|
18
example/server-core-use.cxx
Normal file
18
example/server-core-use.cxx
Normal file
@ -0,0 +1,18 @@
|
||||
#include <server-core.h>
|
||||
#include <iostream>
|
||||
|
||||
class ConsoleApp : public wxApp
|
||||
{
|
||||
public:
|
||||
bool OnInit() override;
|
||||
};
|
||||
|
||||
bool ConsoleApp::OnInit()
|
||||
{
|
||||
CServerCore server;
|
||||
server.Init("127.0.0.1", 9897);
|
||||
server.Run();
|
||||
return false;
|
||||
}
|
||||
|
||||
wxIMPLEMENT_APP(ConsoleApp);
|
0
gui/CMakeLists.txt
Normal file
0
gui/CMakeLists.txt
Normal file
0
gui/main.cxx
Normal file
0
gui/main.cxx
Normal file
0
gui/mainframe.cxx
Normal file
0
gui/mainframe.cxx
Normal file
0
gui/mainframe.h
Normal file
0
gui/mainframe.h
Normal file
16
server-core/CMakeLists.txt
Normal file
16
server-core/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(server-core LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(wxWidgets CONFIG REQUIRED)
|
||||
|
||||
set(PSOURCES
|
||||
server-core.h
|
||||
server-core.cxx
|
||||
)
|
||||
|
||||
add_library(server-core STATIC ${PSOURCES})
|
||||
target_link_libraries(server-core PRIVATE wx::net wx::core)
|
||||
target_include_directories(server-core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
48
server-core/server-core.cxx
Normal file
48
server-core/server-core.cxx
Normal file
@ -0,0 +1,48 @@
|
||||
#include "server-core.h"
|
||||
|
||||
// https://wizardforcel.gitbooks.io/wxwidgets-book/content/133.html
|
||||
|
||||
CServerCore::CServerCore()
|
||||
{
|
||||
}
|
||||
|
||||
CServerCore::~CServerCore()
|
||||
{
|
||||
}
|
||||
|
||||
bool CServerCore::Init(const wxString& ip, unsigned short port)
|
||||
{
|
||||
wxIPV4address addr;
|
||||
addr.Service(port);
|
||||
server_ = std::make_unique<wxSocketServer>(addr, wxSOCKET_NOWAIT);
|
||||
|
||||
if (!server_->IsOk()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
server_id_ = wxNewId();
|
||||
server_->SetEventHandler(*this, server_id_);
|
||||
server_->SetNotify(wxSOCKET_CONNECTION_FLAG); // 1. 设置监听的事件类型
|
||||
server_->Notify(true); // 2. 启用事件通知
|
||||
|
||||
Bind(wxEVT_SOCKET, &CServerCore::OnServerEvent, this, server_id_);
|
||||
return true;
|
||||
}
|
||||
|
||||
int CServerCore::Run()
|
||||
{
|
||||
wxEventLoop loop;
|
||||
return loop.Run();
|
||||
}
|
||||
|
||||
void CServerCore::OnServerEvent(wxSocketEvent& event)
|
||||
{
|
||||
if (event.GetSocketEvent() == wxSOCKET_CONNECTION) {
|
||||
auto* cli = server_->Accept();
|
||||
if (!cli) {
|
||||
return;
|
||||
}
|
||||
wxString tmp("Nihao");
|
||||
cli->Write(tmp.c_str(), tmp.size());
|
||||
}
|
||||
}
|
28
server-core/server-core.h
Normal file
28
server-core/server-core.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef SERVER_CORE_H
|
||||
#define SERVER_CORE_H
|
||||
|
||||
#include <memory>
|
||||
#include <wx/wx.h>
|
||||
#include <wx/socket.h>
|
||||
#include <wx/event.h>
|
||||
#include <wx/evtloop.h>
|
||||
|
||||
class CServerCore : public wxEvtHandler
|
||||
{
|
||||
public:
|
||||
CServerCore();
|
||||
~CServerCore();
|
||||
|
||||
public:
|
||||
bool Init(const wxString& ip, unsigned short port);
|
||||
int Run();
|
||||
|
||||
private:
|
||||
void OnServerEvent(wxSocketEvent& event);
|
||||
|
||||
private:
|
||||
std::unique_ptr<wxSocketServer> server_{};
|
||||
wxWindowID server_id_{};
|
||||
};
|
||||
|
||||
#endif
|
0
server/CMakeLists.txt
Normal file
0
server/CMakeLists.txt
Normal file
0
server/server.cxx
Normal file
0
server/server.cxx
Normal file
0
server/server.h
Normal file
0
server/server.h
Normal file
0
util/CMakeLists.txt
Normal file
0
util/CMakeLists.txt
Normal file
0
util/gutil.cxx
Normal file
0
util/gutil.cxx
Normal file
0
util/gutil.h
Normal file
0
util/gutil.h
Normal file
Loading…
x
Reference in New Issue
Block a user