Implementation of an event-driven chat server.
Authored by Shahar Amram
The program is an Event-Driven Chat Server:
implement an event-driven chat server. The function of the chat is to forward each incoming message’s overall client connections except for the client connection over which the message was received.
program contain 1 file:
The main file.implement an event-driven chat server. The function of the
chat is to forward each incoming message’s overall client connections except for the client connection over which the message was received.
opening the server socket, and after call “select” inside a loop to check from which socket descriptor is ready for reading or writing.
- checkThePort - private function check the port size.
- remove_msg - private function to remove the message that allocated.
- remove_mem - private function to remove and free all the allocated memory in the profram.
- add_conn - function that add connection to the pool.
- remove_conn - function that remove connection from the pool.
- add_msg - function add msg_t to write queue of all the other connections.
- write_to_client - function write all msgs in the queue.
compile : gcc -g -Wall chatServer.c -o server
run: ./server
The input will be from the command line, ont number that represent the port to connect to.
and after each connection that will join with 'telnet' command.
In the terminal you should see the chat between the connection that open, while the server terminal describe the chat flow.
If there is no port parameter, or more than one parameter, or the parameter is not a
number between 1 to 2^16, print "Usage: server ".
For each failure, until ‘select’ is called,perror and exit the server.
If select fails, exit the loop, clean the memory, and exit.
For any other error, skip the operation and continue.