Trying to setup ServerApp program.
This commit is contained in:
@@ -56,6 +56,11 @@ CPMAddPackage(
|
||||
URL https://git.redacted.cc/josh/jjx/archive/Prerelease-2.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME Sockets
|
||||
URL https://git.redacted.cc/josh/Sockets/archive/Prerelease-2.zip
|
||||
)
|
||||
|
||||
add_subdirectory(Core)
|
||||
add_subdirectory(Server)
|
||||
add_subdirectory(Client)
|
||||
|
@@ -15,7 +15,8 @@ target_include_directories(CaveCore PUBLIC "include")
|
||||
|
||||
set_target_properties(CaveCore PROPERTIES LINKER_LANGUAGE CXX)
|
||||
target_include_directories(CaveCore PUBLIC ${J3ML_SOURCE_DIR}/include)
|
||||
target_include_directories(CaveCore PUBLIC ${mcolor}/include)
|
||||
target_include_directories(CaveCore PUBLIC ${mcolor_SOURCE_DIR}/include)
|
||||
target_include_directories(CaveCore PUBLIC ${jjx_SOURCE_DIR}/include)
|
||||
target_include_directories(CaveCore PUBLIC ${Sockets_SOURCE_DIR}/include)
|
||||
|
||||
target_link_libraries(CaveCore PUBLIC J3ML jjx mcolor)
|
||||
target_link_libraries(CaveCore PUBLIC J3ML jjx mcolor Sockets)
|
@@ -1 +1,24 @@
|
||||
cmake_minimum_required(VERSION 3.18..3.29)
|
||||
cmake_minimum_required(VERSION 3.18..3.29)
|
||||
|
||||
file(GLOB_RECURSE CaveServer_HEADERS "include/*.hpp")
|
||||
file(GLOB_RECURSE CaveServer_SRC "src/*.cpp")
|
||||
|
||||
if (UNIX)
|
||||
add_library(CaveServer SHARED ${CaveServer_SRC})
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
add_library(CaveServer SHARED ${CaveServer_SRC})
|
||||
endif()
|
||||
|
||||
target_include_directories(CaveServer PUBLIC
|
||||
${CaveCore_SOURCE_DIR}/include
|
||||
${J3ML_SOURCE_DIR}/include
|
||||
${Sockets_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_include_directories(CaveServer PUBLIC "include")
|
||||
|
||||
set_target_properties(CaveServer PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
target_link_libraries(CaveServer PUBLIC CaveCore J3ML Sockets)
|
@@ -1,4 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.18..3.29)
|
||||
|
||||
file(GLOB_RECURSE CaveServerApp_HEADERS "include/*.hpp")
|
||||
file(GLOB_RECURSE CaveServerApp_SRC "src/*.cpp")
|
||||
|
||||
add_executable(CaveServerApp main.cpp ${CaveServerApp_SRC})
|
||||
|
||||
target_include_directories(CaveServerApp PUBLIC
|
||||
${CaveServer_SOURCE_DIR}/include
|
||||
${J3ML_SOURCE_DIR}/include
|
||||
${Sockets_SOURCE_DIR}/include)
|
||||
|
||||
target_include_directories(CaveClientApp PUBLIC "include")
|
||||
|
||||
target_link_libraries(CaveClientApp PUBLIC CaveServer J3ML Sockets)
|
||||
|
||||
add_executable(CaveServerApp main.cpp)
|
@@ -1,5 +1,8 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <Sockets/UdpServer.hpp>
|
||||
|
||||
class ArgsParser
|
||||
{
|
||||
@@ -16,4 +19,31 @@ public:
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
std::cout << "Starting..." << std::endl;
|
||||
|
||||
UDPServer<> udpServer;
|
||||
|
||||
udpServer.onRawMessageReceived = [&](const char* message, int length, std::string ipv4, uint16_t port)
|
||||
{
|
||||
std::cout << ipv4 << ":" << port << " =>" << message << "(" << length << ")" << std::endl;
|
||||
|
||||
udpServer.SendTo(message, length, ipv4, port);
|
||||
};
|
||||
|
||||
// Bind the server to a port.
|
||||
udpServer.Bind(8888, [](int errorCode, std::string errorMessage) {
|
||||
std::cout << errorCode << ":" << errorMessage << std::endl;
|
||||
});
|
||||
|
||||
// You should do an input loop, so the program won't terminate immediately.
|
||||
|
||||
std::string input;
|
||||
getline(std::cin, input);
|
||||
while (input != "exit") {
|
||||
getline(std::cin, input);
|
||||
}
|
||||
|
||||
udpServer.Close();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user