Skip to content

luv-bansal/MultiThreaded-Load-Balanced-Chat-Room-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Threaded Load Balanced Chat Room Server

Overview

  • This project aims to implement multithreaded chat room servers.

  • It supports multiple client, multiple servers and a Load balancer that uses Round-Robin Load Balancing technique to distribute client load equally on all the servers.

  • This project is compatible for all GNU C++ compilers on UNIX/LINUX based environments.

  • It uses Socket programming and create connection between server and client using TCP.

  • Multithreading ensures parallel communication between multiple clients in multiple chat-rooms.

  • Mutex locks are mapped to each client to avoid race conditions while connection and communication.

Setup and use Locally

  • Clone the repository and change the directory.
  git clone https://github.com/Pasa1912/MultiThreaded-Load-Balanced-Chat-Room-Server.git
  cd MultiThreaded-Load-Balanced-Chat-Room-Server
  • Compile the server.cpp, loadbalancer.cpp and client.cpp files
 g++ server.cpp -lpthread -o server
 g++ loadbalancer.cpp -lpthread -o loadbalancer
 g++ client.cpp -lpthread -o client
  • Run the files sequentially as -

    • Assign a unique port to each of the server that needs to be created. These ports must be consecutive. Run the server file.
        ./server <port>
    • Run the loadbalancer file. It runs on port :6000 by default.
       ./loadbalancer
    • Enter the port of the first server and the total number of servers created.
    • Run the client file and enter Name and Room ID to chat in.
       ./client
    • Keep repeating the above step for every client that needs to be created. Enjoy :)

Working

This project uses Socket Programming in C++ using Transmission Control Protocol( TCP ). The function of the Loadbalancer is to keep record of loads on each server and also keep watch on the servers that are not able to connect to the clients to appropriately distribute traffic equally on each of the working server. The Loadbalancer implemented in this project uses a Dynamic Round-Robin Load Balancing algorithm to equally distribute the client load to the servers. The concept of Multi-threading is used for parallel or concurrent execution of sending and receiving messages simultaneously by each client. Race Conditions that arise during connection and communication of server and client is resolved by mapping a separate mutex lock for each client.

The Gradual Working process of this project is as -

  • The Client first makes a connection request to the Loadbalancer. It sends the details of Client name and Room ID it needs to connect to.
  • The Loadbalancer then makes connection request to each Server and requests for the amount of Client load that Server is currently handling.
  • The Loadbalancer thus compares load on each running Server and thus assigns weight to each server. Thus it directs the Client to the optimally chosen Server.
  • The Client thus makes a connection request to the Server as chosen by Loadbalancer.
  • The Server then accepts the connection request and run a thread for sending and receiving messages from each Client.

This working can be explained using the below Connection Diagram -

Learnings

Gained practical experience in Socket Programming in C++ using Transmission Control Protocol, Load Balancing and Distribution Techniques and Multi-threading concepts. Learnt using mutex locks to prevent race conditions among different threads.

Additional Tasks

  • Used Multithreading to create Multiple Chat Rooms between Multiple Clients.

  • Used Load Balancer to distribute equal loads on Multiple Servers.

Demo Video

Demo.mp4

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages