mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
allow remote IP to be accessed from websocket object
This commit is contained in:
parent
8f26cea2a6
commit
85e85c3e64
@ -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);
|
||||
})
|
||||
|
@ -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; }
|
||||
@ -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).
|
||||
|
Loading…
Reference in New Issue
Block a user