我可以在 @ServletEndpoint
类的 @OnOpen
方法中获取远程 IP 地址吗?
我试着按照这个Accessing HttpSession from HttpServletRequest in a Web Socket @SocketEndpoint但如Websocket - httpSession returns null它不起作用。
无论如何,我只需要客户端 IP 地址。
最佳答案
JSR-356 Websocket 规范不公开客户端 IP 地址。
您可以尝试此回复中描述的 2 种技巧之一: JSR-356 WebSockets with Tomcat - How to limit connections within single IP address?
关于java - Websocket 在连接时获取远程 IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25913760/