HCMUS-Project-Org / ChatGRPC

Chat application use gRPC to communicate between processes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

icon
Chat gRPC

Chat application use gRPC to communicate between processes.

contributors last update forks stars open issues

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


πŸ“– Table of Contents

πŸ“½οΈ Demo

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

πŸ“° Report

Check out the report to see full report.

🧰 Getting Started

πŸ“Œ Prerequisites

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

🦾 How to use gRPC

1. Define your gRPC service using protocol buffers. This will define the messages and methods used for communication.

  1. Define your service in a .proto file using protocol buffer syntax. (chat.proto in /service)

    syntax = "proto3";
    
    service ChatService {
      rpc SendMessage(Message) returns (Message) {}
      rpc ReceiveMessage(Empty) returns (stream Message) {}
    }
    
    message Message {
      string user_name = 1;
      string text = 2;
    }
    
    message Empty {}
    Explain variable

    This defines a:

    • Message type with text and sender fields
    • ChatService with two methods:
      • SendMessage takes a Message object as input and returns a Message object
      • ReceiveMessage takes an empty Empty object as input and returns a stream of Message objects.
  2. Use the generated code to implement your gRPC service.

    python -m grpc_tools.protoc -I /path/to/protos --python_out=. --grpc_python_out=. /path/to/protos/my_service.proto

    Example:

    python3 -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. service/my_service.proto
  3. 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.

    Explain server
    • This defines a ChatServiceServicer class that implements the ChatService defined in chat.proto. The SendMessage function appends the received message to a list of messages and returns the same message. The ReceiveMessage function yields all the messages in the list.

    • The serve function creates a gRPC server and adds the ChatServiceServicer to it. It starts the server on port 50051.

  4. 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.

  5. Start the server process(es) and client process(es).

  6. Use gRPC's built-in functionality to handle the communication between the server and client processes.

πŸ› οΈ Installation

Install application

# Clone this repository
git clone https://github.com/HCMUS-Project/ChatGRPC.git

# Go into the repository
cd ChatGRPC

Run server

python server.py

Run client (open new terminal)

python client.py

Note If you're using Linux Bash for Windows, see this guide or use node from the command prompt.

πŸ’¬ Chat Convention

LIKE reply

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

Syntax: LIKE_<user_id>
Rule:

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

Example: LIKE_01

Exception

Syntax: [<type>] <content>_<user_id>
Program exception:

  • [WARNING] You can not LIKE yourself_<from_user>!
  • [WARNING] You only LIKED: [<user_id>]'s message ONCE!_<from_user>
  • [WARNING] You are NOT allowed to send message_<from_user>
  • [INFO] You LIKED: [<user_id>]'s message_<from_user>

πŸ“„ Log

Log file

Syntax: [<time>] <content>

<!-- logfile.log exapmle  -->
[15:47:47] Quan join group chat - ID(01)
[15:47:54] User[01] send message 'hello'
[15:47:54] User[01] is BLOCKED to send message
[15:48:08] User[01] is not allow to send message
[15:48:15] Van join group chat - ID(02)
[15:48:20] Lien join group chat - ID(03)
[15:48:23] Hao join group chat - ID(04)
[15:48:29] Dat join group chat - ID(05)
[15:48:35] User[05] send message 'hello'
[15:48:35] User[05] is BLOCKED to send message
[15:48:42] User[04] send message 'chao moi nguoi'
[15:48:42] User[04] is BLOCKED to send message
[15:48:51] User[03] send message 'alo alo'
[15:48:51] User[03] is BLOCKED to send message
[15:49:03] User[03] like for User[01]
[15:49:15] User[03] like for User[01]
[15:49:28] User[03] like for User[03]
[15:49:36] User[04] like for User[01]
[15:49:36] User[01] is ALLOWED to send message
[15:49:56] User[01] send message 'hi , i am free'
[15:49:56] User[01] is BLOCKED to send message
[15:50:00] User[01] is not allow to send message

Content

  • Client connect and enter username:
    <username> join group chat - ID(<user_id>)
  • Client send msg success:
    User[<user_id>] send message β€˜<message>
  • Client A like client B's msg:
    User[<userA_id>] like for User[<userB_id>]
  • Client being block send msg but still try sending msg:
    User[<user_id>] is not allow to send message
  • Client has been blocked from sending messages:
    User[<user_id>] is BLOCKED to send message
  • The client is allowed to send messages:
    User[<user_id>] is ALLOWED to send message

πŸ—ΊοΈ Roadmap

  • Complete the server
  • Complete the client
  • Log file
  • Report

πŸ‘₯ 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

Chat application use gRPC to communicate between processes.


Languages

Language:Python 100.0%