Skip to content

ChatServer is a multi-threaded chat server based on TCP long connections, implemented in accordance with multiple network libraries to achieve cluster and load balancing.

License

Notifications You must be signed in to change notification settings

666xz666/ChatServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChatServer

Introduction

ChatServer is a multi-threaded chat server based on TCP long connections implemented in accordance with the muduo network library, achieving cluster and load balancing.

Get Started

Dependencies

  • Muduo (v2.0.2)

  • libmysqlclient-dev (8.0.43-0ubuntu0.22.04.2)

  • Hiredis (1.3.0)

MySQL 、Redis and Nginx

  • edit connection configs:
// include/server/db/db.h
static std::string server = "127.0.0.1";
static unsigned int port = 4406;
static std::string user = "root";
static std::string password = "123456";
static std::string dbname = "chat";

// include/server/redis/redis.hpp
static const char REDIS_IP[] = "127.0.0.1";
static const int REDIS_PORT = 5379;
static const char REDIS_PASSWORD[] = "123456";
  • Nginx conf file:
# /path/to/nginx/conf/nginx.conf

stream {
    upstream backend {
        server 127.0.0.1:6000 weight=1 max_fails=3 fail_timeout=30s;
        server 127.0.0.1:6002 weight=1 max_fails=3 fail_timeout=30s;
    }

    server {
        listen 8000;
                proxy_pass backend;
        tcp_nodelay on;
    }
}

Build and Run

git clone https://github.com/666xz666/ChatServer.git

cd ./ChatServer
mkdir build
cd build
cmake ..

cd ../bin
# server
./ChatServer 127.0.0.1 6000
./ChatServer 127.0.0.1 6002
# client
./ChatClient 127.0.0.1 8000

About

ChatServer is a multi-threaded chat server based on TCP long connections, implemented in accordance with multiple network libraries to achieve cluster and load balancing.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published