Skip to content

Xiaoming94/chat-server

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chit chat server

To build this project, follow the steps below:

cd build
cmake ../
make

This will generate two executables, server and client, which you can run by ./server and ./client respectively.

💬 Server (server.cpp)

  • Create and bind a TCP socket (socket(), bind(), listen())

  • Use select() to handle multiple client sockets

  • Accept new client connections and store their file descriptors

  • Read data from connected clients

  • Broadcast each received message to all other clients

  • Handle client disconnects (remove closed sockets)

👤 Client (client.cpp)

  • Connect to server using socket() + connect()

  • Launch a std::thread to receive messages from server continuously

  • Use the main thread to read user input and send to server

  • Gracefully handle disconnects (e.g., Ctrl+C)

About

Forking to help

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 91.8%
  • CMake 8.2%