socketio.hpp 798 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <string>
  2. #include <cstring>
  3. #include <vector>
  4. #include <iostream>
  5. #include <exception>
  6. #include <cmath>
  7. #include <stdexcept>
  8. #include <stdio.h>
  9. #include <sys/socket.h>
  10. #include <stdlib.h>
  11. #include <netinet/in.h>
  12. class cppsocket{
  13. private:
  14. struct sockaddr_in serv_addr;
  15. int sock;
  16. std::vector<char> buffer;
  17. public:
  18. const static constexpr unsigned int buffersize = 16;
  19. cppsocket(sockaddr_in _serv_addr,int _sock);
  20. cppsocket();
  21. cppsocket(const std::string& addr, unsigned int PORT);
  22. void write(const std::string& message);
  23. std::vector<char> receive();
  24. };
  25. class server_socket{
  26. private:
  27. int port_;
  28. int server_fd;
  29. struct sockaddr_in address;
  30. socklen_t addrlen;
  31. public:
  32. int port();
  33. server_socket(int _port);
  34. cppsocket accept_connection();
  35. };