-
Notifications
You must be signed in to change notification settings - Fork 5
/
client.js
37 lines (32 loc) · 1.12 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var config = require('./lib/config');
var log4js = require('log4js');
log4js.configure({
appenders: {
out: { type: 'stdout' },
client: { type: 'file', filename: 'logs/client.log' }
},
categories: { default: { appenders: ['out', 'client'], level: 'error' } }
});
var logger = log4js.getLogger();
logger.level = config.LOG_LEVEL;
var retry = -1;
var connectClient = require('./lib/client/connectClient');
var connect = function () {
new connectClient(logger, config.GATEWAY, config.CONNECT_PORT, config.CONNECT_SIGN,
config.TRANS_PORT, config.SERVER_HOST, config.SERVER_PORT, function () {
retry = 0;
}, function () {
if (retry >= 5) {
logger.fatal('[connect] Reached limit of retries(5), Exit.');
} else if (retry != -1) {
setTimeout(function () {
retry++;
logger.info('[connect] Retrying. No.' + retry);
connect();
}, 5000);
} else {
logger.fatal('[connect] Failed connecting to server, Exit.');
}
});
}
connect();