3

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 {
     }
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Df.fpm
  • 189
  • 1
  • 5
  • 15

2 Answers2

1

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?

Community
  • 1
  • 1
Df.fpm
  • 189
  • 1
  • 5
  • 15
-1

this is for websocket with spring @Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { System.out.println("connectionestablished!"+session.getLocalAddress());
}

Ajay
  • 87
  • 7
  • its not about jsf ,spring.you can get it from session. – Ajay May 31 '16 at 11:04
  • OP is using standard Java EE, not the 3rd party Spring library. You're not answering the concrete question at all. If you want to answer Spring questions, look for Spring questions. – BalusC May 31 '16 at 11:08