Giter Site home page Giter Site logo

chat's Introduction

chat

C++ boost::asio implementation of multi-threaded chat server, and client

I implemented a console mode chat room using C++11 features and boost::asio asynchronous library. The chat room consists of a chat server and multiple chat clients. The makefile will generate 2 binaries, chat_server and chat_client. The boost::asio::io_service::strand is used to serialize server side event handlers in thread pool. The strand wrapper eliminates the need of explicitly synchronize and locking event handlers in thread pool.

The chat room can perform the following functions:

  1. Broadcast each new chat message to all participants in the same room.
  2. A chat message consists of server time stamp, client’s nickname, and client’s chat content text message.
  3. When a new participant joins a room, all recent chat history will be feed to this participant.
  4. A single server can support multiple chat rooms. Chat rooms are distinguished from each other by port numbers.
  5. The server can be easily configured with multiple threads. Number of threads is hardcoded in the server code just for demonstration purpose. For production use, the number of worker threads need a config file entry.
  6. For Linux system, set cpu affinity to threads in pool is also demonstrated.
  7. Tested across Windows and Linux.

example

starts server on a home computer, with only one room listening on port 8888

$./chat_server 8888

starts 3 clients on another home computer, all connect to the chat_server which is on box 192.168.1.4.

first starts client Botao:

$./chat_client Botao 192.168.1.4 8888

After a few typing messages, starts client Tom:

$./chat_client Tom 192.168.1.4 8888

Finally starts client Mike:

$./chat_client Mike 192.168.1.4 8888

The type in message and console history is like this: image

The chat_server can support multiple room like this:

$./chat_server 8888 9999

now clients can select which room to join based on port numbers.

chat's People

Contributors

botaojia avatar

Watchers

 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.