Serveur.h 1003 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef SERVEUR_H_INCLUDED
  2. #define SERVEUR_H_INCLUDED
  3. #ifdef WIN32
  4. #include <winsock2.h>
  5. typedef int socklen_t;
  6. #else
  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 Serveur
  27. {
  28. public:
  29. Serveur(int port, int nbrClient);
  30. ~Serveur();
  31. bool rendreUtilisable();
  32. void envoyer(void* donnee, int indice, int tailleByte);
  33. void recevoir(void* donnee, int indice, int tailleByte);
  34. private:
  35. #ifdef WIN32
  36. WSADATA m_WSAData;
  37. #endif
  38. Sock m_sock;
  39. Sock *m_csock;
  40. int m_port;
  41. int m_erreur;
  42. const int m_nbrClient;
  43. };
  44. #endif // SERVEUR_H_INCLUDED