Spring4 + websocket notes [including source code]

Source: Internet
Author: User
WebSocket is an important part of HTML5 and is said to have many benefits. So it took a little time to study this dongdong, to see what the goods are evil, what magical powers, can be used for me.

I tried to download the spring official demo (address: Https://github.com/rstoyanchev/spring-websocket-test)
Run up to see a little bug inside, modify it yourself, and read the revisions and annotate the main code. After the revised source code in:
Http://git.oschina.net/sybn/webSocketDemo.git

Here is a fragmented record of the harvest and feelings, and then continue to complement the improvement.

First of all, Spring4 's demo has no XML configuration file, even Web.xml, which is a recommended style of spring. If you're not used to it, it's OK to continue to define the configuration using the original spring.xml configuration file format. Demo with a little spring security things, a little bit more access control.

WebSocket here, you can see that there are many channels in the demo, which are used to push the client and server to send messages to each other.
The client pushes the server to a better understanding, similar to the traditional HTTP schema,

We can give the original controller a little bit of material can be achieved.
@Controller public
class Greetingcontroller {
	@RequestMapping (value= "/greeting", Method=post)
	public void Httpgreet (String text) {
	//...
	}
	@MessageMapping ("/greeting") public
	void Stompgreet (String text) {
	//...
	}
}

The server's push to the client is a bit like a JMS sensation:
This.messagingTemplate.convertAndSend ("/topic/price.stock." + quote.getticker (), quote);

The convertandsend sent here is a broadcast message, and all clients listening to/topic/price.stock.* receive the message.


Guess:
A simple guess where websocket can be shot.
When we use EXT, if using WebSocket instead of Ajax to do the implementation of data proxy, when a person modifies the data, the other person can immediately receive the new version of the data push, reduce the frequency of dirty data appear. Of course, just reduced.


Questions:
The security of this process has not yet been studied, and unauthorized listening is blocked by spring.
At present, if the client reboot, the client can normally reconnect to the server, but not the contrary, it seems that the demo does not do side-fault-tolerant processing. The impact of other network environmental changes has not been studied for the time being. (for example, agent)
The downgrade policy prepared in the demo, if the browser does not support WebSocket, will automatically use the alternative, we do not need to do any additional configuration of this process, after testing UC can be a normal visitor domo.
There is no specific study of the performance of WebSocket, those times websocket performance than the traditional HTTP scheme is not clear, no specific data comparison before Wood has the right to say AH.


Reference documentation
http://www.oschina.net/translate/websocket-architecture-in-spring-4-0
1http://www.iteye.com/news/27808-springframework-websocket

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.