/* ========================================================================== */ /* */ /* server.h */ /* (c) 2008 jocelyne.lecomte@alcatel-lucent.fr */ /* */ /* Description */ /* */ /* ========================================================================== */ #ifndef SERVER_H #define SERVER_H #include #include #include #include #include /* close */ #include /* gethostbyname */ /* socket error */ #define INVALID_SOCKET -1 #define SOCKET_ERROR -1 /* somes values */ #define CRLF "/r/n" #define BUF_SIZE 1024 #define PORT 5004 #define MAX_CLIENTS 100 /* to be more explicit */ typedef int SOCKET; typedef struct sockaddr_in SOCKADDR_IN; typedef struct sockaddr SOCKADDR; typedef struct in_addr IN_ADDR; /* clients */ typedef struct { SOCKADDR_IN sin; char name[BUF_SIZE]; }Client; static int init_connection(void); static void end_connection(SOCKET sock); static int read_client(SOCKET sock, SOCKADDR_IN *sin, char *buffer); static void write_client(SOCKET sock, SOCKADDR_IN *sin, const char* buffer); static void send_msg_to_all_clients(SOCKET sock, Client *clients, Client *client, int actual, const char *buffer, char from_server); static void remove_client(Client *clients, int to_remove, int *actual); static check_if_client_exist(Client *clients, SOCKADDR_IN *csin, int actual); static Client* get_client(Client *clients, SOCKADDR_IN *csin, int actual); void comm(void); #endif