0
I,通過springboot-websocket guide幫忙寫個簡單的WebSocket服務器:關於連接的Spring Java客戶端的WebSocket
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic");
registry.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/endpoint").setAllowedOrigins("*");
stompEndpointRegistry.addEndpoint("/endpoint").setAllowedOrigins("*").withSockJS();
}
}
@Controller
public class P2PMessageController {
@MessageMapping("/hello")
@SendTo("/topic/greetings")
public P2PMessage sayHello(P2PMessage message){
P2PMessage msg=new P2PMessage();
msg.setText("hello");
return msg;
}
}
我的問題:
我可以建立與ws://server/endpoint
連接,但我怎麼能發送消息給/app/hello
並使用java客戶端在/topic/greetings
上訂閱,但不是JavaScript客戶端。
我找不到適合客戶端的java websocket api。
任何幫助將不勝感激。