| 15 | #include <iostream> |
| 16 | |
| 17 | class ChatClient : public CppServer::Asio::SSLClient |
| 18 | { |
| 19 | public: |
| 20 | using CppServer::Asio::SSLClient::SSLClient; |
| 21 | |
| 22 | void DisconnectAndStop() |
| 23 | { |
| 24 | _stop = true; |
| 25 | DisconnectAsync(); |
| 26 | while (IsConnected()) |
| 27 | CppCommon::Thread::Yield(); |
| 28 | } |
| 29 | |
| 30 | protected: |
| 31 | void onConnected() override |
| 32 | { |
| 33 | std::cout << "Chat SSL client connected a new session with Id " << id() << std::endl; |
| 34 | } |
| 35 | |
| 36 | void onHandshaked() override |
| 37 | { |
| 38 | std::cout << "Chat SSL client handshaked a new session with Id " << id() << std::endl; |
| 39 | } |
| 40 | |
| 41 | void onDisconnected() override |
| 42 | { |
| 43 | std::cout << "Chat SSL client disconnected a session with Id " << id() << std::endl; |
| 44 | |
| 45 | // Wait for a while... |
| 46 | CppCommon::Thread::Sleep(1000); |
| 47 | |
| 48 | // Try to connect again |
| 49 | if (!_stop) |
| 50 | ConnectAsync(); |
| 51 | } |
| 52 | |
| 53 | void onReceived(const void* buffer, size_t size) override |
| 54 | { |
| 55 | std::cout << "Incoming: " << std::string((const char*)buffer, size) << std::endl; |
| 56 | } |
| 57 | |
| 58 | void onError(int error, const std::string& category, const std::string& message) override |
| 59 | { |
| 60 | std::cout << "Chat SSL client caught an error with code " << error << " and category '" << category << "': " << message << std::endl; |
| 61 | } |
| 62 | |
| 63 | private: |
| 64 | std::atomic<bool> _stop{false}; |
| 65 | }; |
| 66 | |
| 67 | int main(int argc, char** argv) |
| 68 | { |
nothing calls this directly
no outgoing calls
no test coverage detected