No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Server.java 737B

12345678910111213141516171819202122232425262728293031323334
  1. package websocket;
  2. import javax.websocket.server.*;
  3. import java.io.IOException;
  4. import javax.websocket.*;
  5. @ServerEndpoint("/hello/")
  6. public class Server {
  7. private Session session;
  8. @OnOpen
  9. public void connect(Session session) {
  10. this.session= session;
  11. System.out.println("session :"+ session);
  12. }
  13. @OnClose
  14. public void close() {
  15. this.session=null;
  16. System.out.println("session closed");
  17. }
  18. @OnMessage
  19. public void onMessage(String msg) throws IOException {
  20. System.out.println("msg recu:"+msg);
  21. this.session.getAsyncRemote().sendText("server:"+msg);
  22. //if (this.session != null && this.session.isOpen()) {
  23. // this.session.getBasicRemote().sendText("server:"+msg);
  24. //}
  25. }
  26. }