Client.h 967 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef CLIENT_H_INCLUDED
  2. #define CLIENT_H_INCLUDED
  3. #ifdef WIN32
  4. #include <winsock2.h>
  5. typedef int socklen_t;
  6. #elif defined (linux)
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <netinet/in.h>
  10. #include <arpa/inet.h>
  11. #include <unistd.h>
  12. #define INVALID_SOCKET -1
  13. #define SOCKET_ERROR -1
  14. #define closesocket(s) close (s)
  15. typedef int SOCKET;
  16. typedef struct sockaddr_in SOCKADDR_IN;
  17. typedef struct sockaddr SOCKADDR;
  18. #endif // WIN32
  19. #include <iostream>
  20. struct Sock
  21. {
  22. SOCKADDR_IN sin;
  23. SOCKET sock;
  24. socklen_t recsize;
  25. };
  26. class Client
  27. {
  28. public:
  29. Client(std::string IP, int port);
  30. ~Client();
  31. bool rendreUtilisable();
  32. void envoyer(void* donnee, int tailleByte);
  33. void recevoir(void* donnee, int tailleByte);
  34. private:
  35. #ifdef WIN32
  36. WSADATA m_WSAData;
  37. #endif
  38. Sock m_csock;
  39. std::string m_IP;
  40. int m_port;
  41. int m_erreur;
  42. };
  43. #endif // CLIENT_H_INCLUDED