Last active
December 17, 2015 14:39
-
-
Save zztczcx/5625591 to your computer and use it in GitHub Desktop.
CONNECT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//master.js | |
net.createServer(function(socket){ | |
var worker = workers[lastWorkPos++]; | |
if(lastWorkPos >= numCPUs) lastWorkPos = 0; | |
worker.send({type:'new_client'}, socket, [{ track: false, process: false }]); | |
}).listen(serverSettings.port); | |
//child.js | |
var self = this; | |
process.on("message", function(msg,socket) { | |
if(msg && msg.type == 'new_client' && socket) { | |
var client = mqtt.createConneciton(socket); | |
client.once('connect',function(packet){ | |
// 将client的引用保存到hash表中 | |
client.device_token = packet.device_token; | |
self.clients[client.device_token] = client; | |
}); | |
client.once('close', function(error) { | |
delete self.clients[client.device_token]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment