I have implemented simple backend using Spring boot which supports Stomp Websocket. It takes the message from user and send it to the specific url. Here is the code in spring boot.
Controller
package com.dakshverma.chattime.controller;
import com.dakshverma.chattime.model.Message;
import com.dakshverma.chattime.model.MessageResponse;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import javax.websocket.server.PathParam;
@Controller
public class ChatController {
@MessageMapping("/msg/{t}")
@SendTo("/topic/{t}")
public MessageResponse sendMessage(@PathParam("t") String t, Message message){
return new MessageResponse(message.getText(), message.getUsername());
}
}
Config
package com.dakshverma.chattime.config;
import com.dakshverma.chattime.model.Message;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry){
registry.addEndpoint("/chatsocket").withSockJS();
registry.addEndpoint("/chatsocket");
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry){
registry.enableSimpleBroker("/topic");
registry.setApplicationDestinationPrefixes("/app");
}
}
Can someone explain me how do I connect my android application to the backend?