Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/websocket/example_ws.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main()
CROW_ROUTE(app, "/ws")
.websocket()
.onopen([&](crow::websocket::connection& conn){
CROW_LOG_INFO << "new websocket connection";
CROW_LOG_INFO << "new websocket connection from " << conn.get_remote_ip();
std::lock_guard<std::mutex> _(mtx);
users.insert(&conn);
})
Expand Down
6 changes: 6 additions & 0 deletions include/crow/websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace crow
virtual void send_ping(const std::string& msg) = 0;
virtual void send_pong(const std::string& msg) = 0;
virtual void close(const std::string& msg = "quit") = 0;
virtual std::string get_remote_ip() = 0;
virtual ~connection(){}

void userdata(void* u) { userdata_ = u; }
Expand Down Expand Up @@ -185,6 +186,11 @@ namespace crow
});
}

std::string get_remote_ip() override
{
return adaptor_.remote_endpoint().address().to_string();
}

protected:

/// Generate the websocket headers using an opcode and the message size (in bytes).
Expand Down