node-ipc/test/unix/unixServerSync.js

56 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-07-04 17:12:00 +10:00
import ipc from '../../node-ipc.js';
import process from 'process';
2016-01-10 20:03:05 +11:00
2021-07-04 17:12:00 +10:00
const dieAfter=30e3;
function killServerProcess(){
process.exit(0);
}
2016-01-10 18:23:40 +11:00
setTimeout(
2021-07-04 17:12:00 +10:00
killServerProcess,
2016-01-10 18:23:40 +11:00
dieAfter
);
2016-01-10 18:23:40 +11:00
ipc.config.id = 'unixServerSync';
ipc.config.retry= 1500;
2016-01-10 18:23:40 +11:00
ipc.config.silent=true;
ipc.serve(
2016-01-10 18:23:40 +11:00
function serverStarted(){
2016-01-10 20:03:05 +11:00
let ready=false;
ipc.server.on(
'message',
2016-01-10 18:23:40 +11:00
function gotMessage(data,socket){
2016-01-10 20:03:05 +11:00
if(ready){
ipc.server.emit(
socket,
'message',
{
id : ipc.config.id,
message : 'Error, client not wating for server response before sending request.'
}
);
}
2021-07-04 17:12:00 +10:00
ipc.server.emit(
socket,
'message',
{
id : ipc.config.id,
message : 'Response from unix server'
}
);
}
);
}
);
2021-07-04 17:12:00 +10:00
ipc.server.on(
'END',
killServerProcess
)
ipc.server.start();