List of all members.
Constructor & Destructor Documentation
chatserver::chatserver |
( |
int |
port, |
|
|
bool |
automatic_server_discovery |
|
) |
| |
The constructor of the class chatserver.
- Parameters:
-
port | the port number on which the server will listen for TCP connections |
automatic_server_discovery | true if the automatic server discovery is enabled, false otherwise. |
Member Function Documentation
void* chatserver::broadcast_invitation_tread |
( |
void * |
broadcast_params | ) |
|
Thead that performs the broadcast for the automatic server discovery.
- Parameters:
-
[in] | broadcast_params | all the necessary parameters for the automatic server discovery. |
int chatserver::create_tcp_server_socket |
( |
| ) |
|
This function creates a server socket that listens at a specific port and is binded to all available network interfaces of the host.
- Returns:
- the socket descriptor or -1 if something went wrong. If something failed, a descriptive error message should be printed by using perror() inside this function.
msg_type_t chatserver::get_message_type |
( |
char * |
buffer, |
|
|
size_t |
buf_len |
|
) |
| |
Function that finds the type of the received message.
- Parameters:
-
[in] | buffer | The buffer containing the data received from the client. |
[in] | buf_len | The length of the buffer. |
- Returns:
- the message type. If the type could NOT be found UKNOWN_MSG_TYPE should be returned.
void* chatserver::handle_client_connection_thread |
( |
void * |
thread_parameter | ) |
|
This function runs on a new thread that has been created by they handle_incoming_connections() function, and is responsible for sending and receiving message from the connected client.
If your are curious why the parameter is void *, go to the thread Lab and study it AGAIN carefully.
The thread terminates, when the server is killed by the user.
- Parameters:
-
[in] | thread_parameter | A struct that contains all the appropriate info for the client thread. Use the client_thread_params_t struct that has been casted to void *, as we said at the LAB. |
void chatserver::handle_incoming_connections |
( |
int |
server_socket | ) |
|
This function runs until the user kills the server and waits for incoming connections. When accept() returns a new connection, adds it at the d_connections_list and pass the node (that contains all the necessary that you need) at a new thread that handles the client. The pthread_create() takes as arguement the function handle_client_thread(void *connection_info)
- Parameters:
-
[in] | server_socket | a valid server socket discriptor |
bool chatserver::handle_login_message |
( |
connection_t * |
client_connection, |
|
|
char * |
buffer, |
|
|
size_t |
buf_len |
|
) |
| |
When a login message received, try to login the user. In any case of error this function sends back to the client the appropriate error message. Also if the user succesfully logged in set the username, at the appropriate field of the client_connection node.
- Parameters:
-
[in] | client_connection | the node of the connections_list, that corresponds to the current client. |
[in] | buffer | the data as they received from the client |
[in] | buf_len | the length of the buffer |
- Returns:
- TRUE if the user succesfully logged in FALSE otherwise.
bool chatserver::handle_logout_message |
( |
connection_t * |
client_connection | ) |
|
When a logout message received, logout the client by deleting the node at the connections_list list and closing the established connection.
- Parameters:
-
[in] | client_connection | the node of the connections_list, that corresponds to the current client. |
- Returns:
- TRUE if the user succesfully logged out, FALSE otherwise.
int chatserver::handle_text_message |
( |
connection_t * |
client_connection, |
|
|
char * |
buffer, |
|
|
size_t |
buf_len |
|
) |
| |
Function responsible for propagating a message received from a client, to the right receiver that must be connected and logged in.
- Parameters:
-
[in] | client_connection | the node of the connections_list, that corresponds to the current client. |
[in] | buffer | the data as they received from the client |
[in] | buf_len | the length of the buffer |
- Returns:
- the number of bytes sent, or -1 in case of error. Note that in case of error, this function should send back an error message to the client.
void* chatserver::print_stats_counters_thread |
( |
void * |
refresh_rate | ) |
|
This function runs on a seperate thread and prints every refresh_rate seconds the values of the three counters of the server.
If your are curious why the parameter is void *, go to the thread Lab and study it AGAIN carefully.
- Parameters:
-
[in] | refresh_rate | The interval in seconds between two prints of the counters |
int chatserver::send_back_error_message |
( |
connection_t * |
client_connection, |
|
|
msg_type_t |
error_type, |
|
|
char * |
msg_content, |
|
|
size_t |
msg_content_len |
|
) |
| |
General function that sends back to the client, a specified error message.
- Parameters:
-
[in] | error_type | the message type that describes the desired error. |
[in] | msg_content | the contents of the error message. This can be a discriptive human readable text. |
[in] | msg_content_len | the length in bytes, of the msg_content |
- Returns:
- the number of bytes sent, or -1 in case of error.
int chatserver::send_to_client_online_users |
( |
connection_t * |
client_connection | ) |
|
Function that sends back to the client a list with all the online users.
- Parameters:
-
[in] | client_connection | the node of the connections_list, that corresponds to the current client. |
- Returns:
- The total number of bytes that were sent, or -1 in case of error.
The documentation for this class was generated from the following file: