-
-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I get the IP address of the WebSocket client by crow::websocket::connection? #261
Comments
You can use As for disconnecting, you'll need to keep a map of the connections and their related IP addresses. |
But i can't get |
you can store the connection from Another thing you can do is modify @@ -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). |
Thanks very much!!! |
No problem, thanks for making the suggestion :) |
I want to print the IP address of the WebSocket client when it connects or disconnects to my server
![image](https://user-images.githubusercontent.com/66063199/139561771-cf3811dd-e1f8-4b06-8579-7ff4b56bcdac.png)
The text was updated successfully, but these errors were encountered: