游戏版本公告系统
http://localhost:8080/v1/index.html
http://localhost:8080/v1/admin.html
1、上面两个连接 连接上endpoint 基站 之后
app.js里面 发送到这个"/app/v1/chat" 渠道
function sendName() { stompClient.send("/app/v1/chat", {}, JSON.stringify({'content': $("#content").val()})); }
2、GameInfoController 转发 到 topic/game_chat 渠道
@Controller
public class GameInfoController {
@MessageMapping("/v1/chat")
@SendTo("/topic/game_chat")
public OutMessage gameInfo(InMessage message){
return new OutMessage(message.getContent());
}
}
3、app.js这里显示
function connect() {
var socket = new SockJS('/endpoint-websocket'); //连接上端点(基站)
stompClient = Stomp.over(socket); //用stom进行包装,规范协议
stompClient.connect({}, function (frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/game_chat', function (result) {
console.info(result)
showContent(JSON.parse(result.body));
});
});
}