HY335a-Project
A_multithread_chat_Server_and_chat_client
|
The header file of the chatserver. More...
#include <pthread.h>
Go to the source code of this file.
Classes | |
struct | connection |
struct | client_thread_params |
struct | broadcast_invitation_tread_params |
class | chatserver |
Macros | |
#define | BACKLOG_SIZE 1000 |
Typedefs | |
typedef struct connection | connection_t |
typedef struct client_thread_params | client_thread_params_t |
typedef struct broadcast_invitation_tread_params | broadcast_invitation_tread_params_t |
Enumerations | |
enum | msg_type_t { LOGIN_MSG = 0x1, LOGOUT_MSG = 0x2, TEXT_MSG = 0x3, USERNAME_NOT_EXIST = 0x4, USER_ALREADY_LOGGED = 0x5, USERS_LOGGED_REQUEST = 0x6, USERS_LOGGED_RESPONSE = 0x7, BROADCAST_MSG = 0x8, UKNOWN_MSG_TYPE = 0xFE, GENERAL_ERROR = 0xFF, LOGIN_MSG = 0x1, LOGOUT_MSG = 0x2, TEXT_MSG = 0x3, USERNAME_NOT_EXIST = 0x4, USER_ALREADY_LOGGED = 0x5, USERS_LOGGED_REQUEST = 0x6, USERS_LOGGED_RESPONSE = 0x7, BROADCAST_MSG = 0x8, UKNOWN_MSG_TYPE = 0xFE, GENERAL_ERROR = 0xFF } |
The header file of the chatserver.
This header file contains several structures that are vital, in order to implement your server.
Also contains the declarations of several functions. All the functions below MUST be implemented, WITHOUT changing its parameters or their return types.
Although you are welcome to add your own.
Note that in your program you should use, all of them, having in mind that some of them are called inside some other. Eg handle_client_connection_thread() will definitly called from the handle_incoming_connections() function.
For questions, problems, or bugs of this header file just email me.
May the code be with you... :)
#define BACKLOG_SIZE 1000 |
This is your default backlog size. Use it at the right function.
Pass this struct as parameter to the thread that broadcasts the invitation messages for the automatic server discovery.
typedef struct client_thread_params client_thread_params_t |
At every client thread we pass this struct as parameter that contains all the info that you need.
typedef struct connection connection_t |
In this struct we keep information for every active connection.
The server keeps a list with all the connections. If a new client connects the server adds a node to the list. Until the client performs a loggin, is_logged_in remains FALSE, and username is NULL.
NOTE: Fill free to add your own fields
enum msg_type_t |
The different types of messges. The message type is the first byte of every message from the client to the server and vice versa.
As the message type is only one byte we do not care about endianess problems.
NOTE 1: Each message number is in hexademical form. NOTE 2: Enum in C are at least two bytes, so make sure that you take the right byte when you send it. A simple cast to unsigned char would be enough. (Or not? :P ) NOTE 3: Fill free to add your own message types However, they must be unique, one byte long, and be carefull to be the same at the server and at the client.