2 changed files with 55 additions and 0 deletions
@ -0,0 +1,40 @@ |
|||||
|
package com.xtong.zhbs.service; |
||||
|
|
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
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 |
||||
|
*/ |
||||
|
@Service |
||||
|
@ServerEndpoint("/pl") |
||||
|
public class WsPassFlowService { |
||||
|
/** |
||||
|
* 发送消息 |
||||
|
* @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"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
package com.xtong.zhbs.service; |
||||
|
|
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
|
||||
|
import javax.websocket.Session; |
||||
|
|
||||
|
import static org.junit.Assert.*; |
||||
|
|
||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
||||
|
public class WsPassFlowServiceTest { |
||||
|
WsPassFlowService wsPassFlowService = new WsPassFlowService(); |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue