server.h 1021 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * File: server.h
  3. * Author: Arthur Brandao
  4. *
  5. * Created on 14 novembre 2018
  6. */
  7. #ifndef SERVER_H
  8. #define SERVER_H
  9. /* --- Include --- */
  10. #include <sys/types.h>
  11. #include <sys/socket.h>
  12. #include <arpa/inet.h>
  13. #include "constante.h"
  14. /* --- Constantes --- */
  15. #define SERV_UDP 1
  16. #define SERV_TCP 2
  17. /* --- Structures --- */
  18. typedef struct server* Server;
  19. struct server{
  20. int type; /* Le type de serveur (UDP ou TCP) */
  21. /* Var server */
  22. int socket; /* Socket du serveur */
  23. int socket_client; /* Socket du client (TCP uniquement) */
  24. struct sockaddr_in serv; /* Adresse du serveur */
  25. struct sockaddr_in client; /* Adresse du client */
  26. socklen_t addr;
  27. /* Pointeur de fonction */
  28. boolean (*server_bind)(Server, int);
  29. ssize_t (*server_receive)(Server, char*, size_t);
  30. boolean (*server_send)(Server, char*);
  31. boolean (*server_accept)(Server);
  32. };
  33. /* --- Fonction --- */
  34. Server server_create_udp();
  35. Server server_create_tcp();
  36. void server_close(Server);
  37. boolean server_close_client(Server);
  38. #endif /* SERVER_H */