websocket
https://cdn.bootcss.com/stomp.js/2.3.3/stomp.min.js
https://cdn.jsdelivr.net/sockjs/1/sockjs.min.js
http://blog.csdn.net/PandaWang1989/article/details/54863489?locationNum=5&fps=1
https://www.cnblogs.com/bianzy/p/5822426.html
http://blog.csdn.net/u012373815/article/details/54380476
https://segmentfault.com/a/1190000011908831
===========
http://blog.csdn.net/javaexploreroooo/article/details/52432111
http://blog.csdn.net/soslinken/article/details/53021510
http://blog.csdn.net/jie873440996/article/details/70257558
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <meta charset="utf-8"/> <meta name="renderer" content="webkit|ie-comp|ie-stand"/> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <meta http-equiv="Cache-Control" content="no-siteapp"/> <title>Key to Happiness</title> <link rel="stylesheet" href="/static/css/common.css"/> </head> <body> <header class="navbar-wrapper"> 测试 webSocket <button οnclick="connect()">连接</button> <button οnclick="disconnect()">断开</button> <button οnclick="sendName()">发送信息</button> </header> <script type="text/javascript" src="/static/js/jquery.min.js"></script> <script type="text/javascript" src="/static/js/sockjs.min.js"></script> <script type="text/javascript" src="/static/js/stomp.min.js"></script> <script type="text/javascript"> var stompClient = null; function setConnected(connected){ /*document.getElementById('connect').disabled = connected; document.getElementById('disconnect').disabled = !connected; document.getElementById('conversationDiv').style.visibility = connected ? 'visible' : 'hidden';*/ $("#response").html(); } function connect(){ var socket = new SockJS('/endpointAric'); //连接SockJS的endpoint名称为"endpointWisely" stompClient = Stomp.over(socket);//使用STMOP子协议的WebSocket客户端 stompClient.connect({},function(frame){//连接WebSocket服务端 setConnected(true); console.log('Connected:' + frame); //通过stompClient.subscribe订阅/topic/getResponse 目标(destination)发送的消息,这个是在控制器的@SentTo中定义的 stompClient.subscribe('/topic/getResponse',function(response){ console.log('-----------'); console.log(response); console.log('-----------'); }); }); } function disconnect(){ if(stompClient != null) { stompClient.disconnect(); } setConnected(false); console.log("Disconnected"); } function sendName(){ var name = "测试数据"//$("#name").val(); //通过stompClient.send向/welcome 目标(destination)发送消息,这个是在控制器的@MessageMapping中定义的 stompClient.send("/welcome",{},JSON.stringify({'name':name})); } function showResponse(message){ var response = $("#response"); response.html(message); } </script> </body> </html>