0

我正在使用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

4

1 回答 1

1

根据文档,远程地址是响应的一个属性。尔格:

std::string_view remote_ip = res->getRemoteAddressAsText();
于 2021-10-25T08:32:22.317 回答