TCP server with Boost::Asio

Similar to the Poco chat, a version of chat server using Boost::Asio is given here. Instead of select(), asynchronous calls are used. Smart pointer shared_ptr is used to avoid delete operator.

Structure of the classes session, chat_line and message remain the same.

session.hpp
session.cpp
chat_line.hpp
chat_line.cpp
message.hpp
message.cpp

Handler deals with a single connection using asynchronous send/receive functions.

handler.hpp
handler.cpp

Server accepts new connections in asynchronous manner. Since the Boost::Asio guarantees that callback handlers will only be called from threads that are currently calling io_service::run(), a pool of threads is created to accept them.

server.hpp
server.cpp

Server is started inside main function.

main.cpp

Server is tested under Linux 2.6.37 64bit/gcc 4.5.2/boost 1.47.0, FreeBSD 8.0/gcc 4.2.1/boost 1.47.0, Windows 7/VS 2010/boost 1.47.0, compiled as specified in the Makefile.

Makefile

The presented code can be downloaded as an archive.

ready.

10 print "mail: contact at alepho.com | skype: karastojko | stackoverflow: karastojko | github: karastojko"
20 print "(c) 2009-2023 www.alepho.com"