diff options
author | Tobias Frust <tobiasfrust@gmail.com> | 2016-07-11 15:15:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-11 15:15:32 +0200 |
commit | 8af3d595e2856f81a46a91d67e96f53cb3b25d0f (patch) | |
tree | bd2cb6e80b0db90713f9d24de09577125d6f3d85 /src/main_server.cpp | |
parent | 13783f932576a285b08cf518a6b0d679aac3c897 (diff) | |
parent | 409e2fd20af5620066796e43410a92521376b2c1 (diff) | |
download | ods-8af3d595e2856f81a46a91d67e96f53cb3b25d0f.tar.gz ods-8af3d595e2856f81a46a91d67e96f53cb3b25d0f.tar.bz2 ods-8af3d595e2856f81a46a91d67e96f53cb3b25d0f.tar.xz ods-8af3d595e2856f81a46a91d67e96f53cb3b25d0f.zip |
Merge pull request #1 from tobiasfrust/master
Implemented DetectorSimulator with basic functionalities
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; + +} |