A chat application using gRPC to communicate between processes.
Demo β’ Documentation β’ Report Bug β’ Request Feature
π Table of Contents
An application use gRPC to communicate between processes and allow users chat with each other.
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.
- Efficient Communication
- Language Agnostic
- Strong Typing and Code Generation
- Streaming and Real-Time Capabilities
- Performance and Scalability
- Extensibility and Interoperability
Check out the Demo video to see the app in action.
Check out the Documentation to see full report document.
Detail Documentation:
- 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
- Python: >= 3.10.7
- gRPC tools: gRPC compiler, Install here.
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)
.
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
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
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 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
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
...
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
- 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
Contributions are always welcome!
This software uses the following open source packages:
Distributed under the MIT License. See LICENSE
for more information.
Bento @quanblue Β Β·Β GitHub @QuanBlue Β Β·Β Gmail quannguyenthanh558@gmail.com