Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Spring WebSocket Comments     - Linux CentOS configuration SVN + SVN hook (Server)

- installation process of Matlab 2012a under Ubuntu 14.04 (Linux)

- Installation Docker FAQ on Ubuntu (Linux)

- Linux Security trust with users (Linux)

- How to use the Docker Machine cluster deployment Swarm (Server)

- WordPress plug-ins installed in Ubuntu, enter the subject of FTP and not create directory problem (Server)

- MySQL5.7.10 installation documentation (Database)

- Ubuntu Tutorial - Manually install Oracle Java JDK 8 (Linux)

- CentOS 6.4 installation environment to build Scrapy 0.22 (Linux)

- Linux serial debugging tools xgcom install (Linux)

- Oracle 11g Export guide problem not an empty table (Database)

- How to become a better Node.js developers in 2016 (Programming)

- Hadoop2.0 configuration yarn success (Server)

- VirtualBox modify the size of the virtual machine disk VDI (Linux)

- Teach you how to synchronize Microsoft OneDrive in Linux (Linux)

- Bitmap memory footprint of computing Android memory optimization (Linux)

- SUSE Linux firewall configuration notes (Linux)

- Linux_Logo - output color ANSI Linux distributions logo command-line tool (Linux)

- Linux protobuf-c (Linux)

- Two classic macro definition under Linux (Linux)

 
         
  Spring WebSocket Comments
     
  Add Date : 2017-08-31      
         
         
         
  Beginning with version 4.0 of the Spring Framework supports WebSocket, below I will detail the content Spring WebSocket library. Including Spring Framework is how to support WebSocket way messaging in Web applications, as well as how to use the STOMP protocol application layer protocol --WebSocket sub-protocol.

1, WebSocket protocol description

WebSocket protocol is an important function of RFC-6455 specification defines a Web areas: full-duplex, two-way communication that is between the client and the server. It is an exciting feature in the industry have explored this area for a long time, use of technology, including Java Applet, XMLHttpRequest, Adobe Flash, ActiveXObject, various Comet technology, the server sends events.

 We need to understand that before using WebSocket protocol, you need to use the HTTP protocol used to build the initial handshake. It relies on a mechanism - the establishment of HTTP, request protocol upgrade (or called protocol conversion). When the server agree that it will respond to HTTP status code 101, it agreed handover protocol. Suppose success Handshake via TCP sockets, HTTP protocol Upgrade requests, the client and the server can send messages to each other.

Spring Framework 4.0+ introduces a new module, the spring-websocket module. It provides support for WebSocket communication. It is compatible with Java WebSocket API specification JSR-356, while providing additional functionality

2, WebSocket downgrade option

Browser support for WebSocket is not fast, IE browser is the 10th edition support only. In addition, some agents also limit WebSocket communication tools. Thus, even now to develop WebSocket application downgrade options is essential in order to support the scenario does not work with analog WebSocket API's. Spring Framework provides this transparent downgrade - use SockJS agreement. This program can be configured to automatically switch, without modifying the application code.

3, messaging infrastructure

In addition to using WebSocket challenges of development, there is a difficulty in that design considerations.

 Currently REST architecture is a widely accepted, easy to understand, build infrastructure suitable for modern Web applications. REST architecture relies on a lot of URL, and several HTTP methods, the use of links, the principles remain stateless.

 In contrast WebSocket applications may use only one URL for the initial HTTP handshake. All subsequent messages shared this TCP connection, the message in this connection on the two-way flow. This is seen, it is completely different from the REST architecture, asynchronous, event-driven, message-passing architecture. WebSocket architecture is quite similar to traditional messaging programs (such as JMS, AMQP).

Spring Framework 4.0 introduces a new module --spring-messaging module, which contains a lot from Spring Integration project abstract concepts, such as: Message message, the message channel MessageChannel, message handle MessageHandler like. This module also includes a set of notes, messages can be mapped onto a method with Spring MVC annotation-based programming model similar.

4, WebSocket support sub-protocol

WebSocket is a messaging architecture, it does not specify any particular messaging protocol. It is a thin layer on top of the TCP protocol, you can put the byte stream into the flow of messages (text goods binary). Followed by the application to interpret the message.

 Different HTTP protocol, WebSocket protocol is an application-level protocol, it is very simple, and can not understand the incoming message, the message can not be routed or processed. Therefore, WebSocket protocol is the underlying application-level protocol, on the need for a framework to understand and process the message.

 For this reason, WebSocket RFC defines the use of sub-protocol. During the handshake, the client and server can use the Header section Sec-WebSocket-Protocol to negotiate the use of sub-protocol - that the use of more advanced application-level protocol. Use sub-protocol is not essential, but even without the use of sub-protocols, applications still need to select a message format - allows the client and server mutually understandable format. This format can be customized, or specific frame, or use a standard messaging protocol.

Spring Framework provides support for the use of sub-STOMP protocol.

STOMP, Streaming Text Orientated Message Protocol, directional flow text message protocol. STOMP is a simple messaging protocol, is one for MOM (Message Oriented Middleware, message-oriented middleware) designed a simple text protocol.

STOMP provides a connection format interoperable, allowing the client to any STOMP STOMP message broker (Broker) interacts similar OpenWire protocol (A binary protocol).

5, under what scenario the use WebSocket

In Web applications, client and server side at a higher frequency and lower latency exchange event, suitable for use WebSocket. Therefore, WebSocket for finance, games, collaboration scenarios.

 For other scenarios are not necessarily appropriate. For example, a newsletter subscription needs to display breaking news, the interval of a few minutes long polling is also possible, where the delay is acceptable.

 Even in the low-latency requirements of application scenarios, if the number of message transmission is low (such as monitoring a network failure scenarios), you should consider using long polling technique.

And only in the high-frequency and low-latency messaging scenarios, the choice of WebSocket protocol is very appropriate. Even with such scenarios, there is still a choice WebSocket communication it? Or choose REST HTTP communication it?

 The answer is based on the needs of the application may be. However, it is possible to use both techniques, the need for frequent exchange of data into the WebSocket achieve, and the REST API as a process of realization of business technology. In addition, when the REST API calls need to broadcast information to a plurality of clients it is to be achieved through a WebSocket connection.

Spring framework provides @Controller @RestController comments and notes, both of which can be used to handle processing and WebSocket message HTTP request. In addition, Spring MVC request processing method, processing method or request other applications, you can easily use WebSocket protocol to broadcast messages to all interested customers or end users specified.
     
         
         
         
  More:      
 
- Ubuntu and derivative system users how to install Pinta 1.5 (Linux)
- Ubuntu and derivatives installation Atom 0.104.0 (Linux)
- Lambda expressions of evolution (Programming)
- On Android running ClojureScript (Linux)
- Ubuntu dual-card system configuration method (Server)
- RHEL5.x RHEL6.x replace CentOS yum source (Linux)
- MySQL common functions summary (Database)
- Iptables Instructions (Linux)
- Linux Workstation Security Checklist - from the Linux Foundation Internal (Linux)
- 17 How to install the Ubuntu 14.04 and Linux Mint Kodi14 (XBMC) (Linux)
- Detailed use Zabbix monitoring Nginx (Server)
- Installation in lxml Python module (Linux)
- MySQL display operation control tips (Database)
- ActiveMQ5.11.1 and JDK version matching relation (Linux)
- Drawing from the Android source code analysis View (Programming)
- ogg start being given libnnz11.so: can not open shared object file (Database)
- Introduction to Linux Shell (Programming)
- Java memory model subclasses (Programming)
- Ten to improve the efficiency of the Linux bash tricks (Linux)
- Linux Change ssh port and disable remote root login at (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.