HY335a-Project
A_multithread_chat_Server_and_chat_client
 All Data Structures Files Functions Variables Typedefs Enumerations Macros
Macros | Typedefs | Enumerations | Functions
chatclient.h File Reference

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)

Detailed Description

The header file of the chatclient.

Author:
surli.nosp@m.gas@.nosp@m.csd.u.nosp@m.oc.g.nosp@m.r

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 Documentation

typedef char boolean

An easy way to support boolean type in C


Enumeration Type Documentation

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.


Function Documentation

int connect_to_server ( int  port,
char *  ip 
)

Function that creates a socket that is connected with the server.

Parameters:
[in]portthe port of the server
[in]ipthe ip of the server
Returns:
the socket with the connections with the server or -1 in case of error.
msg_type_t get_message_type ( char *  buffer,
size_t  buf_len 
)

Function that finds the type of the received message.

Parameters:
[in]bufferThe buffer containing the data received from the server.
[in]buf_lenThe length of the buffer.
Returns:
the message type. If the type could NOT be found UKNOWN_MSG_TYPE should be returned.