HY335a-Project
A_multithread_chat_Server_and_chat_client
|
The header file of the chatclient. More...
#include <stddef.h>
Go to the source code of this file.
Macros | |
#define | TRUE 1 |
#define | FALSE 0 |
Typedefs | |
typedef char | boolean |
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 } |
Functions | |
int | connect_to_server (int port, char *ip) |
msg_type_t | get_message_type (char *buffer, size_t buf_len) |
The header file of the chatclient.
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.
For questions, problems, or bugs of this header file just email me.
May the code be with you... :)
typedef char boolean |
An easy way to support boolean type in C
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. r 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.
int connect_to_server | ( | int | port, |
char * | ip | ||
) |
Function that creates a socket that is connected with the server.
[in] | port | the port of the server |
[in] | ip | the ip of the server |
msg_type_t get_message_type | ( | char * | buffer, |
size_t | buf_len | ||
) |
Function that finds the type of the received message.
[in] | buffer | The buffer containing the data received from the server. |
[in] | buf_len | The length of the buffer. |