简体   繁体   中英

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. HttpServletRequest.getRemoteAddr() works fine, but getRemotePort() returns 0?

Port 0 isn't valid. 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.

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.

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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