I have a socket server / client working well together, however I want to start recording events when the server is offline when the page loads or during a normal run.
I include the remote socket.io code in my header:
<script src="<?=NODE_HOST?>/socket.io/socket.io.js"></script> <script> var nodeHost = '<?=NODE_HOST?>'; </script>
And in my client controller I have
if (typeof io! = 'undefined')
this.socket = io.connect (this.settings.server);
else
this.handleDisconnect ();
A function that I should try to reconnect again and again if: a) the connector is disconnected during normal operation or b) the server is disconnected when the page loads
botController.prototype.handleDisconnect = function () {
$ .getScript (nodeHost + "/ socket.io/socket.io.js").done(function(script, textStatus) {
bot.control.socket = io.connect (bot.control.settings.server);
}). fail (function (jqxhr, settings, exception) {
setTimeout (function () {
bot.control.handleDisconnect ();
}, 5000);
});
}
Am I doing it right?
The main problem that I am currently facing (which made me create this question) is my code errors when loading the page when the server is offline, because I have features such as:
socket.on (...
If the socket does not exist yet. Can I wrap them in a function and call it when I discover that a global socket object exists on successful reconnection? Does it matter if this function, which contains socket.on ..., is called several times (if the server does not work more than once during operation)?
Titan source share