SPRING4 provides support for WebSocket, but online demos are used in the context of spring MVC.
In fact, Spring-websocket is not dependent on SPRINGMVC.
The key is to map the WebSocket address to the URL for triggering the front end.
Also, the first time WebSocket is invoked via HTTP.
In other words, the first request from the client is HTTP. Not websocket.
Here there is evidence of the author.
Open the browser console. We can see.
We can see that the HTTP response code is 101 and the HTTP request header has a upgrade field with a value of websocket.
Now we map the WebSocket code to the servlet
Map the WebSocket address to the servlet
@Override
protected void DoPost (HttpServletRequest req, httpservletresponse RESP)
throws Servletexception, IOException {
ApplicationContext context = Webapplicationcontextutils
. Getwebapplicationcontext (Req.getservletcontext ());
WebSocket's processor
Websockethttprequesthandler handler = new Websockethttprequesthandler (
Context.getbean (" MyHandler ", Myhandler.class));
WebSocket Handshake Processor
list
Full code address in: http://download.csdn.net/detail/u013803262/9899775
Reference from: http://blog.csdn.net/aitangyong/article/details/50533414