client.hpp 806 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef DIST_CLIENT_HPP
  2. #define DIST_CLIENT_HPP
  3. #include <iostream>
  4. #include <sys/socket.h>
  5. #include <sys/fcntl.h>
  6. #include <netinet/in.h>
  7. #include <arpa/inet.h>
  8. #include <strings.h>
  9. #include <unistd.h>
  10. #include "message.hpp"
  11. using namespace std;
  12. class Client{
  13. protected:
  14. void send_message(Message& msg);
  15. bool has_message;
  16. Message message;
  17. public:
  18. char Buffer[MAX_MSG_SIZE];
  19. int socket_fd;
  20. Client(string server_ip,int server_port);
  21. ~Client();
  22. void send_code(char l);
  23. void send_string(string str);
  24. void listen();
  25. void get_message();
  26. };
  27. inline
  28. Client::~Client(){
  29. close(socket_fd);
  30. }
  31. inline void
  32. Client::send_message(Message& msg){
  33. send(socket_fd,msg.buffer,msg.size,0);
  34. }
  35. inline void
  36. Client::send_code(char c){
  37. Message msg;
  38. msg.set_code(c);
  39. send_message(msg);
  40. }
  41. #endif