需要IP地址作为速率限制的字符串 - Rust Actix

问题描述 投票:1回答:1

我正在尝试在websocket应用程序中实现基于IP地址的速率限制器,但我无法弄清楚如何将IP地址作为字符串。我一直在搜索文档,而且没有提到IP地址。

我有一个addr: Recipient<WSMessage>和一个上下文。

到目前为止,我已经尝试过ctx.address() - 无法转换为字符串msg.addr.tx.0 - 不能unbox bc私有。

rust rust-actix actix-web
1个回答
1
投票

弄清楚了:

fn chat_route(req: &HttpRequest<WsChatSessionState>) -> Result<HttpResponse, Error> {
    ws::start(
        req,
        WSSession {
            id: 0,
            hb: Instant::now(),
            ip: req.connection_info().remote().to_string(),
        },
    )
}
© www.soinside.com 2019 - 2024. All rights reserved.