added fork test

This commit is contained in:
logsol 2012-07-28 17:50:34 +02:00
parent 330e537c6a
commit 27b2e135db
2 changed files with 47 additions and 0 deletions

27
fork/child.js Executable file
View file

@ -0,0 +1,27 @@
console.log('spawned');
process.on('message', function (message, handle) {
var pack = message.split(':'),
command = pack[0],
data = pack[1];
switch(command) {
case 'id':
console.log('This is child #' + data);
break;
case 'server':
console.log('child #' + data + ' got server.', handle);
break;
case 'socket':
console.log('child #' + data + ' got socket.', handle);
handle.on('data', onSocketMessage);
break;
}
});
function onSocketMessage (data) {
console.log('onSocketMessage', data.toString('utf-8'));
}