@@ -365,8 +365,12 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
365365
366366 case LWS_CALLBACK_ESTABLISHED:
367367 {
368+ // Get client IP address
369+ char ip_address[64 ];
370+ lws_get_peer_simple (wsi, ip_address, sizeof (ip_address));
371+
368372 // Instanciate a new client
369- std::shared_ptr<IClient> client (new Client (wsi));
373+ std::shared_ptr<IClient> client (new Client (wsi, ip_address ));
370374 server->m_clients [wsi] = client;
371375
372376 // Notify connection
@@ -465,13 +469,22 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
465469}
466470
467471/* * @brief Constructor */
468- LibWebsocketServer::Client::Client (struct lws * wsi) : m_wsi(wsi), m_connected(true ), m_listener(nullptr ), m_send_msgs() { }
472+ LibWebsocketServer::Client::Client (struct lws * wsi, const char * ip_address)
473+ : m_wsi(wsi), m_ip_address(ip_address), m_connected(true ), m_listener(nullptr ), m_send_msgs()
474+ {
475+ }
469476/* * @brief Destructor */
470477LibWebsocketServer::Client::~Client ()
471478{
472479 disconnect (true );
473480}
474481
482+ /* * @copydoc const std::string& IClient::ipAddress(bool) const */
483+ const std::string& LibWebsocketServer::Client::ipAddress () const
484+ {
485+ return m_ip_address;
486+ }
487+
475488/* * @copydoc bool IClient::disconnect(bool) */
476489bool LibWebsocketServer::Client::disconnect (bool notify_disconnected)
477490{
0 commit comments