我正在使用uWebSockets做一个项目。我需要做的是从传入的 HTTP 请求中获取发件人 IP 地址。在文档中,我可以看到 IP 地址可以从WebSockets中取出。有人有想法将 uWS 转换为 WebSockets以获取数据,还是有其他方法可以获取数据?
#include <iostream>
#include "App.h"
int main() {
/* Overly simple hello world app */
uWS::App().get("/*", [](auto *res, auto *req) {
// **this is the place i need to access the ip address of the incoming HttpRequest**
res->end("Hello world!");
}).listen(3000, [](auto *listen_socket) {
if (listen_socket) {
std::cout << "Listening on port " << 3000 << std::endl;
}
}).
run();
std::cout << "Failed to listen on port 3000" << std::endl;
}
库链接:https ://unetworking.github.io/uWebSockets.js/generated/interfaces/WebSocketBehavior.html