websocket notes

Reference:
https://spring.io/guides/gs/messaging-stomp-websocket/
https://www.jianshu.com/p/4ef5004a1c81
https://juejin.im/post/5ce942c3f265da1bbd4b501f#heading-16

To allow cross-domain server

@Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/gs-guide-websocket").setAllowedOrigins("*").withSockJS();
    }

Monitor server interfaces
, like and restcontroller, difference is that the result is sent to the client through the socket simpMessagingTemplate

@RequestMapping("/serverSendMsg")
    @ApiOperation("serverSendMsg")
    public String greetingx(String id) throws Exception {
        simpMessagingTemplate.convertAndSend("/topic/greetings/"+id, new Greeting("Hellfffffffffffo, " + id + "!"));
        return "success";
    }

Long connection is required to use nginx ip hash of fixed forwarded to the background of a machine, or can not find the server returns a socket

Just complete the handshake connection is established, then they have to do things is to write another way to do client server interaction

The method of transmission method client, server message was received
The method of clent listening, server messaging process

Do client connection retry, data idempotent

Guess you like

Origin www.cnblogs.com/yszzu/p/11778704.html