Code Monkey home page Code Monkey logo

sepehr-messenger's Introduction

Drone (cloud)

یه پیام دارم برای علی بابای عزیز

.....

Simple chat server

In this project I implemented a vary simple chat server using golang in which each client writes a message and the server broadcasts the message to all other clients.

How was it implemented? (gRPC)

I have used gRPC to write less, simpler and more efficient code.

gRPC is an open source remote procedure call (RPC) system, using this framework I no longer had to keep the TCP connection open 😃 and also wrote much less code.

🗣️Let's get deeper, I had implemented this server char without gRPC and what I had to do was initiating a TCP connection and keep it open so the server and client can talk to each other using this connection but as you know it wastes our resources, there may be connections which no one writes to for a long time.

gRPC works in a request/response manner so the client initiates a connection and sends its request to server then the server responds and the connection will be closed everything was looking good till I thought about realtime chat 🤔 if a client wants to read its messages so many times in a short time then the previous open TCP connection manner is better than opening a lot of new connections, it led me to use gRPC stream keyword which keeps the connection open.To sum it up when a user wants to read its messages it initiates a TCP connection which will be closed after there is no write action for 10 seconds.

How to use gRPC?

First of all I had to write the functions I needed in a .proto file and then I could compile the file to go file using

protoc -I go_compiled_file_directory proto_file_directory --go_out=plugins=grpc:.

sepehr-messenger's People

Contributors

elahe-dastan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.