2016-03-23 18:07:37 +11:00
|
|
|
const ipc=require('../../../node-ipc');
|
2015-09-27 20:32:14 +10:00
|
|
|
|
|
|
|
/***************************************\
|
|
|
|
*
|
|
|
|
* You should start both hello and world
|
|
|
|
* then you will see them communicating.
|
|
|
|
*
|
|
|
|
* *************************************/
|
|
|
|
|
2016-01-10 23:18:14 +11:00
|
|
|
ipc.config.id = 'world';
|
2015-09-27 20:32:14 +10:00
|
|
|
ipc.config.retry= 1500;
|
|
|
|
ipc.config.rawBuffer=true;
|
|
|
|
ipc.config.encoding='ascii';
|
|
|
|
|
|
|
|
ipc.serveNet(
|
|
|
|
function(){
|
|
|
|
ipc.server.on(
|
|
|
|
'connect',
|
|
|
|
function(socket){
|
2017-02-15 00:23:49 +11:00
|
|
|
|
|
|
|
//manually assign id to group clients if desired
|
|
|
|
if(!ipc.server.of.rawBufferClient){
|
|
|
|
ipc.server.of.rawBufferClient=[];
|
|
|
|
}
|
|
|
|
socket.id='rawBufferClient';
|
|
|
|
ipc.server.of.rawBufferClient.push(socket);
|
|
|
|
|
2015-09-27 20:32:14 +10:00
|
|
|
ipc.server.emit(
|
|
|
|
socket,
|
|
|
|
'hello'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
ipc.server.on(
|
|
|
|
'data',
|
|
|
|
function(data,socket){
|
2016-03-23 18:07:37 +11:00
|
|
|
ipc.log('got a message', data,data.toString());
|
2015-09-27 20:32:14 +10:00
|
|
|
ipc.server.emit(
|
|
|
|
socket,
|
|
|
|
'goodbye'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2017-02-15 00:23:49 +11:00
|
|
|
|
|
|
|
ipc.server.on(
|
|
|
|
'socket.disconnected',
|
|
|
|
function(socket,id){
|
|
|
|
ipc.log('DISCONNECTED from ',id,'\n\n');
|
|
|
|
}
|
|
|
|
);
|
2015-09-27 20:32:14 +10:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
ipc.server.start();
|