【发布时间】:2021-10-25 08:17:20
【问题描述】:
我正在使用 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
【问题讨论】:
-
这个库是用c++写的,我也在用c++。(我是个初学者)
-
请使用您现在拥有的应用程序的代表性示例编辑您的问题,并指出您需要发件人 IP 的位置。
标签: c++ api websocket uwebsockets