2 changed files with 41 additions and 6 deletions
@ -0,0 +1,40 @@ |
|||||
|
package com.xtong.zhbs.webscoket; |
||||
|
|
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.websocket.OnClose; |
||||
|
import javax.websocket.OnMessage; |
||||
|
import javax.websocket.OnOpen; |
||||
|
import javax.websocket.Session; |
||||
|
import javax.websocket.server.ServerEndpoint; |
||||
|
import java.io.IOException; |
||||
|
|
||||
|
/** |
||||
|
* 客流接口 |
||||
|
* websocket |
||||
|
*/ |
||||
|
@Component |
||||
|
@ServerEndpoint("/pl") |
||||
|
public class WsPassFlow { |
||||
|
/** |
||||
|
* 发送消息 |
||||
|
* @param json |
||||
|
* @param session |
||||
|
* @throws IOException |
||||
|
*/ |
||||
|
@OnMessage |
||||
|
public void onMessage(String json, Session session) throws IOException { |
||||
|
session.getBasicRemote().sendText(json); |
||||
|
} |
||||
|
|
||||
|
@OnOpen |
||||
|
public void onOpen(){ |
||||
|
// do nothing
|
||||
|
System.out.println("web socket open"); |
||||
|
} |
||||
|
|
||||
|
@OnClose |
||||
|
public void onclose(){ |
||||
|
System.out.println("webscoket close"); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue