You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
845 B

  1. #ifndef __BETACORE_SERVER_HPP__
  2. #define __BETACORE_SERVER_HPP__
  3. #include <vector>
  4. #include <algorithm>
  5. #include <iostream>
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <sys/poll.h>
  9. #include <netinet/in.h>
  10. #include <signal.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <unistd.h>
  15. #include <thread>
  16. #include <utility>
  17. #include <functional>
  18. #include "common.hpp"
  19. namespace betacore
  20. {
  21. class Server
  22. {
  23. private:
  24. fd_set rset;
  25. bool online = false;
  26. bool server_running= false;
  27. int port;
  28. int server_socket;
  29. std::vector<int> clients;
  30. struct sockaddr_in server_address;
  31. void start();
  32. void shutdown();
  33. void listener();
  34. void read_socket(int client);
  35. void forward_message(int client,char buffer[BUFFER_LENGTH] );
  36. public:
  37. Server(int port);
  38. void off();
  39. bool running();
  40. };
  41. } // namespace betacore
  42. #endif