forked from Roave/shorty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-cluster-example.js
executable file
·66 lines (57 loc) · 2.13 KB
/
server-cluster-example.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/local/bin/node
/**
* This file is part of Shorty.
*
* Shorty is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3 of the License.
*
* Shorty is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Shorty. If not, see <http://www.gnu.org/licenses/>.
*
* @category shorty
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPL
* @copyright Copyright 2010 Evan Coury (http://www.Evan.pro/)
* @package examples
*/
var shorty = require('./lib/shorty'),
util = require('util'),
cluster = require('cluster'),
numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
var shortyServer = shorty.createServer('config.json');
shortyServer.on('bind', function(client, pdu, callback) {
callback("ESME_ROK");
});
shortyServer.on('bindSuccess', function(client, pdu) {
console.log(client.config.system_id + ' bound to pid ' + process.pid);
});
shortyServer.on('deliver_sm_resp', function(client, pdu) {
console.log("sms marked as delivered: " + pdu.sequence_number);
});
shortyServer.on('submit_sm', function(client, pdu) {
console.log(mySms.sender + ' -> ' + mySms.recipient + ': ' + mySms.message);
console.log("submit_sm from " + client.config.system_id);
// Any messages sent from this number will fail
if (mySms.sender === "15555551234") {
// indicate failure
responseCallback(mySms, false, messageId++);
} else {
// indicate success
responseCallback(mySms, true, messageId++);
}
});
shortyServer.start();
}