Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting client IP ADDRESS when using ServerEndpoint

Means, that it will get connections from many users in local web. How can i get IP address each single connection? I use JSR356.

@ServerEndpoint(value = "/ws/example")
public class ExampleServlet {

     private static final AtomicInteger connectionIds = new AtomicInteger(0);
     private static final Set<ExampleServlet> connections = new CopyOnWriteArraySet<>();
     private Session session;

     @OnOpen
     public void start(Session session) {
         this.session = session;
         connections.add(this);
     }

     @OnClose
     public void end() {
     }

     @OnMessage
     public void incoming(String message) {
     }

     @OnError
     public void onError(Throwable t) throws Throwable {
     }
}
like image 562
Df.fpm Avatar asked Mar 10 '26 07:03

Df.fpm


1 Answers

Unfortunately, JSR356 Websocket specification does not expose client IP address. Solution, how to hack this, i found there: JSR-356 WebSockets with Tomcat - How to limit connections within single IP address?

like image 66
Df.fpm Avatar answered Mar 13 '26 02:03

Df.fpm