项目作者: SaCavid

项目描述 :
Messenger example
高级语言: Go
项目地址: git://github.com/SaCavid/Simple-messenger.git
创建时间: 2021-03-19T07:11:00Z
项目社区:https://github.com/SaCavid/Simple-messenger

开源协议:

下载


Simple-messenger

Simple messenger golang app.

Small Html, Bootstrap, Jquery chat app created for testing. ~16 hour lost for all code.

App starting Tcp, Tls, Http server.
Port numbers and other configuration can be changed in env file:

Tcp port: 2500

Tls port: 2501

Http port: 80

As communication protocol simple Json object have been used:

  1. let message = {
  2. "From":"", // Message sender
  3. "To":"", // Message addressed to
  4. "Data":"", // Message content
  5. "Status":"", // Internal use for stop go routines
  6. "Users":"" // Simple Users list
  7. }

Scenario

  1. 1. Connected users must send 1 message for login with message.From = "Sender Username"
  2. 2. After succesfull "Simple login" message with users list will be send to logged users.
  3. 3. After login user can send message to all users in users list.
  4. 4. If new user connected to network checkIn message will be send to all connected users with "users
  5. updated list" (Overloads server if there will be many connections)

Have been used Golang:

  1. 1. Interfaces
  2. 2. Methods
  3. 3. Channels
  4. 4. Goroutines for concurrent connections

At the moment all users in a tcp, tls and http (websocket) can see and message each other.

Feature

  1. 1. Login system must be improved
  2. 2. Database support must be added. Will be enough Postgres and Redis.
  3. 3. Protocols must be improved for better network traffic and speed.
  4. 4. Pool must be added on connect of users. It will stop overload on mass connections
  5. (mostly after restart of server)
  6. 5. Channels can cach only 8 messages at moment. Must be improved with database support.
  7. 6. Security must be improved between ports.

Tested

  1. # Tested for 15-20 minutes. used RAM 0.3 - 0.4 Gb. All users connected Tls server.
  2. Every user sended message every 1 second to randomly selected user.
  3. Every second sended 10k * 10k messages
  4. example message = {
  5. "From":"tlsUser10000",
  6. "To":"tlsUser9999",
  7. "Data":"Looking for new solution",
  8. "Status":false,
  9. "Users":""
  10. }
  11. # Machine specifications
  12. Windows 10 Pro
  13. Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz 3.60 GHz
  14. 64-bit operating system, x64-based processor
  15. RAM 16.0 GB
  16. # Result
  17. 1. Number of goroutines: 20005
  18. 2. Connected users: 10000
  19. 3. Send messages: 31466356
  20. 4. Received Messages: 31466365
  21. 5. Lost packages: 9 (under 0.1% - Mostly not correct timing calculation difference)

Test tools

Used Resources

  1. https://gobyexample.com/
  2. https://certificatetools.com/
  3. https://pkg.go.dev/
  4. https://gist.github.com/denji/12b3a568f092ab951456
  5. https://getbootstrap.com/
  6. https://jquery.com/
  7. https://bootsnipp.com/snippets/1ea0N