简体   繁体   English

Java Servlet返回远程端口0?

[英]Java Servlet Returns Remote Port of 0?

I'm using a servlet deployed on Google AppEngine to respond with the client's remote port number. 我正在使用部署在Google AppEngine上的servlet来响应客户端的远程端口号。 HttpServletRequest.getRemoteAddr() works fine, but getRemotePort() returns 0? HttpServletRequest.getRemoteAddr()工作正常,但getRemotePort()返回0?

Port 0 isn't valid. 端口0无效。 I've tried other IP services that told me normal port numbers (ie 55046 or something) but my servlet returns 0 every time it is accessed from a browser or from Java code. 我尝试了其他IP服务,这些服务告诉我正常的端口号(即55046或其他名称),但是每次从浏览器或Java代码访问它时,我的servlet都会返回0。

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. 我的最终目标是能够在查找收件人的地址和外部端口位置时告诉连接发起者,以便TCP穿孔技术能够正常工作。

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? NAT路由器不使用代理端口吗?

I'm not sure why getRemotePort would return 0, but for your end goal knowing the client port is useless. 我不确定为什么getRemotePort将返回0,但是对于您的最终目标,知道客户端端口是无用的。 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. 实际上,如果第一个连接使用55046,则客户端端口的全部意义在于新连接使用另一个未使用的客户端端口号。

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. 如果您只想允许从该客户端地址进行访问,则需要的是服务器端口,服务器地址以及可选的客户端地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM