Reputation: 23
I referred to this spring boot doc to create web socket in spring boot.
I used stompjs and sockjs-client
var socket = new SockJS('/gs-guide-websocket');
//gives an error in below line
stompClient = Stomp.over(socket);
stompClient.connect({}, function (frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/greetings', function (greeting) {
showGreeting(JSON.parse(greeting.body).content);
});
});
Upvotes: 2
Views: 3825
Reputation: 487
use this stompjs and socket-client
then import them
import SockJS from 'sockjs-client';
import Stomp from 'stompjs';
to connect websocket
//use your link here
var sock = new SockJS('http://localhost:8102/api/ws');
let stompClient = Stomp.over(sock);
sock.onopen = function() {
console.log('open');
}
stompClient.connect({}, function (frame) {
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/public', function (greeting) {
console.log(greeting);
//you can execute any function here
});
});
Upvotes: 4