summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Eisenmann <esperantanaso@gmail.com>2018-05-05 23:43:06 -0400
committerJohn Eisenmann <esperantanaso@gmail.com>2018-05-05 23:43:06 -0400
commit45b2f7219140e2bb3047816203d58b1771b2d710 (patch)
tree656f50a1f53d423e055f88fa7f630a54c883b76c
parent549aa5b4dad6d4f0bc5d877d05e1655dae536556 (diff)
Retry when socket fails
-rw-r--r--routes/index.js17
1 files changed, 16 insertions, 1 deletions
diff --git a/routes/index.js b/routes/index.js
index 4cbd41b..27116d4 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -380,7 +380,22 @@ router.ws("/gameUpdate", checkAuthentication(SOCKET_ERROR_OUTPUT), function(ws,
});
function performUpdate(commandList) {
gameUtils.performUpdate(req.session.username, commandList, function(result) {
- ws.send(JSON.stringify(result));
+ var tempRetryCount = 0;
+ function tryToSendResponse() {
+ try {
+ ws.send(JSON.stringify(result));
+ } catch (error) {
+ console.log(error);
+ if (tempRetryCount < 3) {
+ console.log("Trying to send response again.");
+ setTimeout(tryToSendResponse, 100);
+ tempRetryCount += 1;
+ } else {
+ console.log("Exceeded maximum number of retries.");
+ }
+ }
+ }
+ tryToSendResponse();
});
}
});