问题描述
我使用的是部署在谷歌的AppEngine与客户端的远程端口号响应的servlet。 HttpServletRequest.getRemoteAddr()工作正常,但getRemotePort()返回0?
I'm using a servlet deployed on Google AppEngine to respond with the client's remote port number. HttpServletRequest.getRemoteAddr() works fine, but getRemotePort() returns 0?
端口0是无效的。我已经试过了告诉我正常的端口号等IP服务(即55046或东西),但我的servlet返回0每次从浏览器或从Java code访问时间。
Port 0 isn't valid. I've tried other IP services that told me normal port numbers (i.e. 55046 or something) but my servlet returns 0 every time it is accessed from a browser or from Java code.
我的最终目标是能够在查找收件人的地址和外部端口的位置告诉连接发起者所以TCP打洞技术将正常工作。
My end goal is being able to tell a connection initiator upon lookup the recipient's address and external port location so a TCP hole punching technique will work properly.
是什么原因呢?我怎样才能得到实际的端口号(如果可能的话)?请问NAT路由器不使用代理服务器的端口?
What is the reason for this? How can I get the actual port number (if possible)? Does a NAT router not use a proxy port?
推荐答案
我不知道为什么会getRemotePort返回0,但对你的最终目标知道客户端端口是没用的。客户端端口被重新分配为每个连接。事实上,如果第一连接使用55046,客户端端口的整点为新的连接使用不同的,和未使用的客户端端口号
I'm not sure why getRemotePort would return 0, but for your end goal knowing the client port is useless. The client port gets reassigned for every connection. In fact, if the first connection uses 55046, the whole point of the client port is for a new connection to use a different, and unused client port number.
这使得在防火墙策略中配置了一个洞是无用的信息。您不需要在客户端的端口。你需要的是服务器端口,服务器地址,以及可选的客户端地址,如果你只希望允许来自该客户端地址的访问。
This makes it useless information for configuring a hole in the firewall policy. You will not need the client port. What you need is the server port, the server address, and optionally the client address if you only want to allow access from that client address.
这篇关于的Java Servlet返回0远程端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!