2021-07-03 11:37:53 +10:00
|
|
|
import ipc from '../../node-ipc.js';
|
|
|
|
import process from 'process';
|
2015-12-05 13:40:38 +11:00
|
|
|
|
2021-07-04 15:44:09 +10:00
|
|
|
const dieAfter = 30e3;
|
|
|
|
|
|
|
|
function killServerProcess(){
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
2016-01-10 18:23:40 +11:00
|
|
|
setTimeout(
|
2021-07-04 15:44:09 +10:00
|
|
|
killServerProcess,
|
2016-01-10 18:23:40 +11:00
|
|
|
dieAfter
|
|
|
|
);
|
2015-12-05 13:40:38 +11:00
|
|
|
|
2021-07-04 15:44:09 +10:00
|
|
|
ipc.config.id = 'udp4Server';
|
2015-12-05 13:40:38 +11:00
|
|
|
ipc.config.retry= 1500;
|
2016-01-10 18:23:40 +11:00
|
|
|
ipc.config.silent=true;
|
2016-01-10 21:39:14 +11:00
|
|
|
ipc.config.networkPort=8095;
|
|
|
|
|
2015-12-05 13:40:38 +11:00
|
|
|
ipc.serveNet(
|
2021-07-04 15:44:09 +10:00
|
|
|
'127.0.0.1',
|
2015-12-05 13:40:38 +11:00
|
|
|
'udp4',
|
2016-01-10 18:23:40 +11:00
|
|
|
function serverStarted(){
|
2015-12-05 13:40:38 +11:00
|
|
|
ipc.server.on(
|
|
|
|
'message',
|
2016-01-10 18:23:40 +11:00
|
|
|
function gotMessage(data,socket){
|
2021-07-04 15:44:09 +10:00
|
|
|
//console.log(data,socket)
|
|
|
|
ipc.server.emit(
|
2015-12-05 13:40:38 +11:00
|
|
|
socket,
|
|
|
|
'message',
|
|
|
|
{
|
|
|
|
id : ipc.config.id,
|
2016-01-08 10:55:06 +11:00
|
|
|
message : 'I am UDP4 server!'
|
2015-12-05 13:40:38 +11:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2021-07-04 15:44:09 +10:00
|
|
|
|
|
|
|
ipc.server.on(
|
|
|
|
'END',
|
|
|
|
killServerProcess
|
|
|
|
);
|
2015-12-05 13:40:38 +11:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
ipc.server.start();
|