summaryrefslogtreecommitdiffstats
path: root/src/main_server.cpp
blob: 90b383507eaad7289736879548ee527531c2d769 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "UDPServer/UDPServer.h"
#include "ReceiverThreads/ReceiverThreads.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;

   ReceiverThreads(address, 10, 27);

//   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;

}