Transférer les fichiers vers ''
This commit is contained in:
父節點
72d6f53020
當前提交
9633bf0f5d
共有 1 個文件被更改,包括 34 次插入 和 0 次删除
34
Server.java
Normal file
34
Server.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package websocket;
|
||||
|
||||
import javax.websocket.server.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.websocket.*;
|
||||
|
||||
@ServerEndpoint("/hello/")
|
||||
public class Server {
|
||||
private Session session;
|
||||
|
||||
@OnOpen
|
||||
public void connect(Session session) {
|
||||
this.session= session;
|
||||
System.out.println("session :"+ session);
|
||||
}
|
||||
|
||||
@OnClose
|
||||
public void close() {
|
||||
this.session=null;
|
||||
System.out.println("session closed");
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onMessage(String msg) throws IOException {
|
||||
System.out.println("msg recu:"+msg);
|
||||
this.session.getAsyncRemote().sendText("server:"+msg);
|
||||
//if (this.session != null && this.session.isOpen()) {
|
||||
// this.session.getBasicRemote().sendText("server:"+msg);
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
載入中…
Reference in a new issue