在Websocket API for Java EE 7中获取远程对等方的IP地址 [英] Getting IP Address of the remote peer in Websocket API for Java EE 7
问题描述
如何在Java Glassfish的Websocket API中获取远程对等方的IP地址?
How can I get the IP address of the remote peer in Websocket API for Java Glassfish ?
推荐答案
Another method, based on this answer to another question, is to get the headers of the HandshakeRequest. The headers you are looking for are either of the following.
origin: [IP Address]
x-forwarded-for: [Possibly a separate IP]
为清楚起见,这是我的设置以及如何发现它:
Just for clarity, here's my setup, and how I discovered this:
- MyMachine上的Wamp 2.5:6060.这将托管一个客户端HTML页面.
- LabMachine:6060(正常连接)和LabMachine:6443(安全连接)上的Wamp 2.5.这充当代理.
- 在MyMachine:8080(正常)和MyMachine:8181(SSL)上运行的GlassFish 4.0.这是终点.
我通过自己的计算机,实验室计算机和同事的计算机连接到客户端页面.在每种情况下,WebSocket请求的原始标头都是
I connected to the client page via my own machine, the lab machine, and a colleague's machine. In every case, the origin header of the WebSocket request was
但是,在每种情况下, x-forwarded-host 标头都不同,与实际客户端的IP地址匹配.
However, in each case the x-forwarded-host header was different, matching the IP addresses of the actual client.
这篇关于在Websocket API for Java EE 7中获取远程对等方的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!