- SERVER_PORT #### - This is the port number. This value must be the same value in Client.c. Default value is 6341.
- MAX_PENDING # - This is the number of clients than can be pending for the socket accept(). Default value is 5.
- MAX_CHATROOMS # - This is the number of available chatrooms that are running within the server. Default value is 5.
- MAX_PER_CHATROOM # - This is maximum number of users allowed in each chatroom. Default value is 5.
- MAXNAME ### - This is the value in bytes of the allowed size for structure components within a data packet. This value must be the same value in Client.c. Default value is 256.
- CHATROOM_REFRESH_TIME # - This is the number of seconds that a chatroom will pause before checking the packet buffer and distributing the pending packets. Once distributed the packet is removed from the buffer. Default value is 2.
- PACKET_BUFFER_SIZE # - This is the number of packets that are allowed to be buffered, or pending, for each chatroom. Each buffer is emptied each time a chatroom refreshes. Default value is 5.
(No parameters are needed to execute Server.c.)
After execution Server.c will run indefinitely until a fatal error occurs or the user terminates the program. Client.c consists of only two constants that can be changed.
- SERVER_PORT #### - This is the port number. This value must be the same value in Server.c. Default value is 6341.
- MAXNAME ### - This is the value in bytes of the allowed size for structure components within a data packet. This value must be the same value in Server.c. Default value is 256.
- [IP_ADDRESS] - IP address for Server.c. Example: 127.0.0.1
- [USERNAME] - This is the username that will be used to identify the user within the chatroom. Example: John
- [CHATROOM_ID] - This is the ID of the chatroom which is an integer. Chatroom ID's start at 0 and increment by one. If 5 chatrooms are allowed in Server.c then the available chatroom IDs would be 0,1,2,3 and 4. Example: 1
After the checks are made the join_handler then adds the clien information to the registration table and assigns a new thread to the client which executes the messageDelegate function. This function runs in a loop waiting to receive data froma client. After assigning the client to a thread the join_handler thread terminates and the main loop continues. When a client sends a data packet the respective client thread running the messageDelegate function adds the datapacket to a data buffer for the respective chatroom. At each refresh that the multicaster function exhibits for each chatroom the respective data packet buffer is emptied and the data is broadcast to each client.
Each client instance runs a seperate thread to receive data packets. This allows the client to listen for packets while also waiting for the user to input some text to send. When a client disconnects the associated messageDelegate function puts this update into an deletion queue and then terminates the thread. At next refresh the chatroom then removes the client information from the registration table and client thread array freeing up a spot for another potential client.