4
有人請讓我知道如何連接到從Android客戶端的春天跺腳網絡套接字。Android的春天跺腳網絡套接字客戶端
WebSocketConfig.java
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/pushticket");
config.setApplicationDestinationPrefixes("/rest");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ticket").withSockJS();
}
}
PushMessageNotifier.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
@Service
@EnableAsync
public class PushMessageNotifier {
private SimpMessagingTemplate simpMessagingTemplate;
@Autowired
public PushMessageNotifier(SimpMessagingTemplate simpMessagingTemplate) {
this.simpMessagingTemplate = simpMessagingTemplate;
}
@Async
public Boolean pushToUI(TicketView ticketView) {
Boolean result = false;
if (null != ticketView) {
this.simpMessagingTemplate.convertAndSend("/pushticket/ticket", ticketView);
result = true;
}
return result;
}
}
請告訴我,我怎麼可以連接到從Android應用此套接字?即使我不知道我需要使用哪個Android客戶端連接到此套接字和主題。 在此先感謝