| 13 | #include <iostream> |
| 14 | |
| 15 | class ChatSession : public CppServer::Asio::SSLSession |
| 16 | { |
| 17 | public: |
| 18 | using CppServer::Asio::SSLSession::SSLSession; |
| 19 | |
| 20 | protected: |
| 21 | void onConnected() override |
| 22 | { |
| 23 | std::cout << "Chat SSL session with Id " << id() << " connected!" << std::endl; |
| 24 | } |
| 25 | |
| 26 | void onHandshaked() override |
| 27 | { |
| 28 | std::cout << "Chat SSL session with Id " << id() << " handshaked!" << std::endl; |
| 29 | |
| 30 | // Send invite message |
| 31 | std::string message("Hello from SSL chat! Please send a message or '!' to disconnect the client!"); |
| 32 | SendAsync(message.data(), message.size()); |
| 33 | } |
| 34 | |
| 35 | void onDisconnected() override |
| 36 | { |
| 37 | std::cout << "Chat SSL session with Id " << id() << " disconnected!" << std::endl; |
| 38 | } |
| 39 | |
| 40 | void onReceived(const void* buffer, size_t size) override |
| 41 | { |
| 42 | std::string message((const char*)buffer, size); |
| 43 | std::cout << "Incoming: " << message << std::endl; |
| 44 | |
| 45 | // Multicast message to all connected sessions |
| 46 | server()->Multicast(message); |
| 47 | |
| 48 | // If the buffer starts with '!' the disconnect the current session |
| 49 | if (message == "!") |
| 50 | Disconnect(); |
| 51 | } |
| 52 | |
| 53 | void onError(int error, const std::string& category, const std::string& message) override |
| 54 | { |
| 55 | std::cout << "Chat SSL session caught an error with code " << error << " and category '" << category << "': " << message << std::endl; |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | class ChatServer : public CppServer::Asio::SSLServer |
| 60 | { |
nothing calls this directly
no outgoing calls
no test coverage detected