stomp-js / stompjs

Javascript and Typescript Stomp client for Web browsers and node.js apps
Apache License 2.0
763 stars 81 forks source link

Disconnect stomp socket repeatedly though there has internet connection #183

Closed IhChowdhury closed 4 years ago

IhChowdhury commented 4 years ago

I am trying to make an chat application. I am facing problem that After connecting stomp It disconnect though there has internet connection in my pc. Than I tried several steps to reconnect again:

  1. I have tried below code from your documentation to reconnect it. But if I use this code it could not connect ever. So I leave this steps.

var client = Stomp.over(function(){ return new SockJS(url); });

    // Add the following if you need automatic reconnect (delay is in milli seconds)
    client.reconnect_delay = 5000; 
  1. Then I tried to reconnect stomp again using below code . This method worked but it repeatedly disconnect with my server.

function initialize() { var socket = new SockJS('/service-sockect'); stompClient = Stomp.over(socket); stompClient.connect({}, function (frame) { successCallBack(); }, function (message) { console.log("Disconnected"); showNotice(1,"Server Connection Lost. Reconnecting...",'green'); reconnect('/service-sockect');

});

};

function reconnect(socketUrl) { var connected = false; let reconInv = setInterval(() => { ws = new WebSocket(socketUrl); stompClient = webstomp.over(ws); stompClient.connect({}, function (frame) { connected = true; successCallback(); }, function (message) { showNotice(1,"Server Connection Lost. Reconnecting...",'green'); if(connected){ reconnect(socketUrl); }
}); }, 1000);

};

** Now give me your opinion how can solve this issue.

kum-deepak commented 4 years ago

Could not understand your code. I guess you are trying a create an new application. The following resources should help you:

IhChowdhury commented 4 years ago

Yeah, I have built a chat application using spring boot framework which uses stomp . Though we can exchange messages but very frequently we see socket get disconnected. to solve this i have tried above things recommend the the article. but it can not reconnect automatically again once disconnect. my application is hosted in aws beanstalk and i have seen this disconnect behavior in all browser.

I applied var client = Stomp.over(function(){ return new SockJS(url); });
After creating client stomp using this code then my socket connection can not established. I have found this code in one of stomp documentation.

kum-deepak commented 4 years ago

Please use the resources I have suggested above.