cainawuha / Pro-Spring-5th-notes

0 stars 0 forks source link

WebSocket #2

Open cainawuha opened 3 years ago

cainawuha commented 3 years ago

The WebSocket protocol has two parts: a handshake between the client and server and then data transfer. During the data transfer portion of thecommunication, both the client and server can send messages to each other simultaneously sending messages using Simple (or Streaming) Text-Oriented Message Protocol (STOMP) over SockJS/WebSocket. WebSocket transforms bytes into messages and transports them between client and server. WebSocket lends itself well to applications that have a high frequency of message passing and require low- latency communications

如果浏览器不支持WebSocket,可以用SockJS模拟支持

STOMP is called http for web websocket include: WebSocketConfig, Message(get from UI). Message Wrapper(add some contents and push back to UI,即response). Message Controller(receive message from UI, edit it, to the broker ), Browser user

cainawuha commented 3 years ago

@MessageMapping("/user"): map message to user,即访问user的map到这个方法上, @SendTo("/user/topic"): the message will be sending to, to broker Endpoint is where websocket is created.

UI: create two buttons to manage WebSocket connection. One is to connect, one is to disconnect. UI with a message input, and a button add javascript to send and receive messages from server. spring provides low-level WebSocket API directly.

cainawuha commented 3 years ago

A POST request creates a resource. The server assigns a URI for the new resource, and returns that URI to the client. A PUT request creates a resource or updates an existing resource. The client specifies the URI for the resource.

This principle is known as HATEOAS, or Hypertext as the Engine of Application State. { "rel":"customer", "href":"https://adventure-works.com/customers/3", "action":"DELETE", "types":[] }, This is all the information that a client application needs to be able to invoke the operation. The set of links that are returned may change, depending on the state of the resource. This is what is meant by hypertext being the "engine of application state."

cainawuha commented 3 years ago

build a hypermedia-driven REST service with Spring HATEOAS