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.
- 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;
}
}
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
