如何使用WebSocket连接从服务器发送JSON数组作为响应

时间:2019-09-09 14:00:26

标签: spring-websocket

我已经在Spring Boot应用程序和客户端android应用程序之间实现了Web套接字连接,我能够发送消息和接收消息,但是我无法发送JSON数组作为响应


import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic");
        config.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        System.out.println("connection triggered");
        registry.addEndpoint("/websocket").setAllowedOrigins("*").withSockJS();
    }

}```

0 个答案:

没有答案