diff options
Diffstat (limited to 'src/main_server.cpp')
-rw-r--r-- | src/main_server.cpp | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/src/main_server.cpp b/src/main_server.cpp index 167dfca..a645f49 100644 --- a/src/main_server.cpp +++ b/src/main_server.cpp @@ -1,28 +1,60 @@ #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[]){ - std::cout << "Receiving UDP packages: " << std::endl; + initLog(); + + std::string address = "localhost"; + int port = 4002; + + UDPServer server = UDPServer(address, port); - std::string address = "10.0.0.10"; - int port = 4000; + std::size_t length{32768}; - UDPServer server = UDPServer(address, port); + std::vector<unsigned short> buf(16000); - std::size_t length{16*500}; + std::cout << "Receiving UDP packages: " << std::endl; - unsigned short buf[length]; +// for(auto i = 0; i < 27; i++){ +// std::function<void(void)> f = [=]() { +// server.recv(); +// }; +// start(); +// } - server.recv((char *)buf, length*sizeof(unsigned short)); + 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); - for(auto i = 0; i < length; i++){ - printf("%i ", buf[i]); - } - printf("\n"); + BOOST_LOG_TRIVIAL(debug) << "Server: Received " << bytes << " Bytes with Index " << index; + } - return 0; + return 0; } |