When I try to connect my frontend application made in angular with my server made with java to send some objects from java to angular but the connection is refused and an error like this appears: GET http://localhost:8082/socket.io/?EIO=3&transport=polling&t=MzE0pAX net::ERR_CONNECTION_REFUSED. What can cause this kind of problem?
The Angular Code:
import * as Stomp from 'stompjs';
import * as Socket from 'socket.io-client';
serverUrl = 'http://localhost:8082/ws'
notify= "/notify/activity"
initializeWebSocketConnection(){
let ws = new Socket(this.serverUrl);
this.stompClient = Stomp.over(ws);
let that = this;
this.stompClient.connect({}, function(frame) {
that.stompClient.subscribe(this.notify, (message) => {
this.dangerousActivity=message;
console.log(message);
});
});
}
The Java code:
@MessageMapping("/send/message")
public void onReceivedMesage(String message){
this.template.convertAndSend("/notify", new SimpleDateFormat("HH:mm:ss").format(new Date())+"- "+message);
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/socket")
.setAllowedOrigins("*")
.withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app")
.enableSimpleBroker("/notify");
}
Aucun commentaire:
Enregistrer un commentaire