diff options
Diffstat (limited to 'src/main_server.cpp')
-rw-r--r-- | src/main_server.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main_server.cpp b/src/main_server.cpp new file mode 100644 index 0000000..6e936e4 --- /dev/null +++ b/src/main_server.cpp @@ -0,0 +1,66 @@ +#include "UDPServer/UDPServer.h" + +#include <boost/log/core.hpp> +#include <boost/log/trivial.hpp> +#include <boost/log/expressions.hpp> + +#include <iostream> +#include <string> +#include <thread> + +void initLog() { +#ifndef NDEBUG + boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::debug); +#else + boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info); +#endif +} + +void start(std::function<void(void)> func){ + std::thread([func]() { + while (true) + { + func(); + } + }).detach(); +} + +int main (int argc, char *argv[]){ + + initLog(); + + std::string address = "localhost"; + int port = 4002; + + UDPServer server = UDPServer(address, port); + + std::size_t length{32768}; + std::size_t lastIndex{0}; + + std::vector<unsigned short> buf(16000); + + std::cout << "Receiving UDP packages: " << std::endl; + +// for(auto i = 0; i < 27; i++){ +// std::function<void(void)> f = [=]() { +// server.recv(); +// }; +// start(); +// } + + while(true){ + int bytes = server.recv((char*)buf.data(), length); + std::size_t index = *((std::size_t *)buf.data()); + if(index%1000 == 99) printf("%lu\n", index); + + if(lastIndex != (index-1)) + BOOST_LOG_TRIVIAL(warning) << "Packet loss or wrong order!"; + + lastIndex = index; + + BOOST_LOG_TRIVIAL(debug) << "Server: Received " << bytes << " Bytes with Index " << index; + } + + return 0; + +} |