Skip to content

QuanBlue/chat-grpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

icon
Chat gRPC

A chat application using gRPC to communicate between processes.

contributors last update forks stars open issues license

Demo β€’ Documentation β€’ Report Bug β€’ Request Feature


screenshot

πŸ“– Table of Contents

πŸ’« Introduction

An application use gRPC to communicate between processes and allow users chat with each other.

What is gRPC?

gRPC (Google Remote Procedure Call) is an open-source, high-performance remote procedure call (RPC) framework developed by Google. It allows communication between client and server applications in a distributed system, enabling them to call methods or functions on remote systems as if they were local.

Key features of gRPC include: Language-agnostic, Protocol Buffers, Bi-directional Streaming, Strong Typing and Code Generation, Interoperability, Performance.

gRPC is widely used in various domains, including microservices architectures, cloud-native applications, and distributed systems. It simplifies the development of client-server communication, promotes code reusability, and enables the building of scalable and performant applications.

Why gRPC?

  • Efficient Communication
  • Language Agnostic
  • Strong Typing and Code Generation
  • Streaming and Real-Time Capabilities
  • Performance and Scalability
  • Extensibility and Interoperability

🌟 About the Project

πŸ“· Screenshots

Welcome Figure 1: Welcome UI

Chatbox Figure 2: Chatbox UI

Command Figure 3: App command

Sever log Figure 4: Server log

πŸ“½οΈ Demo

Check out the Demo video to see the app in action.

πŸ“° Documentation

Check out the Documentation to see full report document.

Detail Documentation:

⭐ Features

  • CLI interface
  • Interact, customize command
  • Server - Client
  • Communication between processes - gRPC
  • Voting - At least 2 other users LIKE the before msg to send new msg
  • Log file

🧰 Getting Started

πŸ“Œ Prerequisites

  • Python: >= 3.10.7
  • gRPC tools: gRPC compiler, Install here.

🦾 How to use gRPC

Step 1: Define your gRPC service using protocol buffers.

Refer to Service documentation for more information.

Step 2: Implement the server-side code for your gRPC service. This will handle incoming requests and provide responses. You can create a new process for each instance of your gRPC server.

Refer to Server documentation for more information.

Step 3: Implement the client-side code for your gRPC service. This will send requests to the server and receive responses. You can create one or more client processes as needed.

Refer to Client documentation for more information.

Step 4: Start the server process and client process(es).

πŸ“ Folder structure

This project has the following file structure:

chat-grpc/                      # Root directory of the project
β”œβ”€β”€ README.md                   # Markdown file with project information
β”œβ”€β”€ LICENSE                     # File specifying the project's license
β”œβ”€β”€ .gitignore                  # File specifying Git ignore patterns
β”œβ”€β”€ assets/                     # Directory for project assets
β”‚   β”œβ”€β”€ image1.png
β”‚   β”œβ”€β”€ image2.png
β”‚   └── image...
β”œβ”€β”€ logs/                       # Directory for log files
β”‚   └── logfile.log
β”œβ”€β”€ utils/                      # Directory for utility files
β”‚   β”œβ”€β”€ helper.png
β”‚   └── logger.py
β”œβ”€β”€ services/                   # Directory for service-related files
β”‚   β”œβ”€β”€ proto/                  # Directory for protocol buffer definition files
β”‚   β”‚   β”œβ”€β”€ chat.proto
β”‚   β”‚   β”œβ”€β”€ share_type.proto
β”‚   β”‚   └── user.proto
β”‚   β”œβ”€β”€ grpc_generated/         # Directory for generated gRPC files
β”‚   β”‚   β”œβ”€β”€ chat_pb2.py
β”‚   β”‚   β”œβ”€β”€ chat_pb2_grpc.py
β”‚   β”‚   β”œβ”€β”€ share_type_pb2.py
β”‚   β”‚   β”œβ”€β”€ share_type_pb2_grpc.py
β”‚   β”‚   β”œβ”€β”€ user_pb2.py
β”‚   β”‚   └── user_pb2_grpc.py
β”‚   └── README.md
β”œβ”€β”€ client/                     # Directory for client-related files
β”‚   β”œβ”€β”€ _client.py
β”‚   └── README.md
└── server/                     # Directory for server-related files
    β”œβ”€β”€ _server.py
    β”œβ”€β”€ services_class/         # Directory for service-specific classes
    β”‚   β”œβ”€β”€ user_service.py
    β”‚   └── chat_service.py
    └── README.md

πŸ› οΈ Run Locally

Install application

# Clone this repository
git clone https://github.com/QuanBlue/chat-grpc.git

# Go into the repository
cd chat-grpc

Run server

python3 ./server/_server.py

Run client (open new terminal)

python3 ./client/_client.py

Note: Run multiple client by using multiple terminal

πŸ’¬ Command

We provide a CLI interface for the client. The CLI interface allows users to interact with the chat application with simple commands:

--like [user id]             like for user's message,
--name-len [limit length]    limit the length of the user name. Default is 10,
--frame-width [limit length]   limit the length of the frame. Default is 60,
--padding [limit length]     padding of the content in frame. Default is 2,
--history [limit length]     limit the number of messages in the chat history. Default is 9999,
--help                       show all commands with description,

πŸ€– Like message rule

LIKE reply: for allow user XX to continue chat (at least 2 LIKE)

Command: --like [user id]

Rule:

  • Only LIKE once per user
  • Can not LIKE your self

Example: --like 01

πŸ“„ Log

Log file

Syntax: <yyyy-mm-ddd hh-mm-ss> [TYPE] <content>

<!-- logs/logfile.log exapmle  -->

2023-06-27 09:32:31 [INFO] Server started on port 50051...
2023-06-27 09:32:35 [INFO] User[01]Quan created Successfully!
2023-06-27 09:32:38 [INFO] User[01] send message: hello
2023-06-27 09:32:38 [INFO] User[01] updated successfully!
2023-06-27 09:32:46 [ERROR] User[01] can not LIKE yourself!
2023-06-27 09:37:01 [ERROR] Getting user! User[adaw] not found!
2023-06-27 09:49:42 [ERROR] User[01] is BLOCKED to send message
2023-06-27 09:49:48 [INFO] User[02]Lien created Successfully!
2023-06-27 09:49:50 [INFO] User[01] updated successfully!
2023-06-27 09:49:50 [INFO] User[02] like for user[01]
2023-06-27 09:49:55 [ERROR] User[01] only LIKED: [01]'s message ONCE!
2023-06-27 09:50:42 [ERROR] User[01] can not LIKE yourself!
2023-06-27 09:51:05 [INFO] User[03]Dat created Successfully!
2023-06-27 09:49:50 [INFO] User[03] like for user[01]
2023-06-27 09:51:07 [INFO] User[01] updated successfully!
2023-06-27 09:51:07 [INFO] User[01] is ALLOWED to send message
...

Content

Server start success:

[INFO] Server started on port 50051...

Client connect and enter username:

[INFO] User[<user_id>]<username> created Successfully!
[ERROR] User[<user_id>]<username> created Fail!

Client send msg success:

[INFO] User[<user_id] send message: <message>

Update Client stat (like, block, allow):

[INFO] User[<user_id>] updated successfully!
[ERROR] Getting user! User[<user_id>] not found!

Client A like client B's msg:

[INFO] User[<userA_id>] like for User[<userB_id>]
[ERROR] User[<userA_id>] only LIKED: [<userB_id>]'s message ONCE!
[ERROR] User[<userA_id>] can not LIKE yourself!

The client is allowed/blocked to send messages:

[INFO] User[<user_id>] is ALLOWED to send message
[ERROR] User[<user_id>] is BLOCKED to send message

πŸ—ΊοΈ Roadmap

  • UI
  • Command line - customize UI (padding, table width,...)
  • Communication
  • Logs
  • Multi-threading (client)
  • Chatting rule - At least 2 LIKE (from 2 others) to continue chat
  • Demo
  • Documentation

πŸ‘₯ Contributors

Contributions are always welcome!

✨ Credits

This software uses the following open source packages:

πŸ“œ License

Distributed under the MIT License. See LICENSE for more information.


Bento @quanblue Β Β·Β  GitHub @QuanBlue Β Β·Β  Gmail quannguyenthanh558@gmail.com

About

A chat application uses gRPC to communicate among processes.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages