JSR-356 Websocket specification does not expose the client IP which is why HttpServletRequest.getRemoteAddr()
returns null
.
This also explains why HttpServletRequest.getRemoteAddr()
returns an empty string or 0.0.0.0 depending on the version of Atmosphere you are using because Atmosphere alters the HttpServletRequest
.
Although the Tomcat 7 documentation on Websockets states "Tomcat implements the Java WebSocket 1.1 API defined by JSR-356", when I run Tomcat version 7.0.68, which is the current Tomcat 7 version, HttpServletRequest.getRemoteAddr()
still returns the client IP address via websocket. This is true when I run Tomcat with Java 6, 7, or 8.
The Tomcat 8 documentation on Websockets also states "Tomcat implements the Java WebSocket 1.1 API defined by JSR-356" and when running the same application on Tomcat 8 that I ran on 7, HttpServletRequest.getRemoteAddr()
returns an empty string.