socketio.hpp 806 B

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