2014-02-22 20:13:31 +11:00
|
|
|
var ipc=require('../../../node-ipc');
|
|
|
|
|
|
|
|
/***************************************\
|
2016-01-04 20:22:37 +11:00
|
|
|
*
|
2014-03-02 09:31:40 +11:00
|
|
|
* UDP Client is really a UDP server
|
2016-01-04 20:22:37 +11:00
|
|
|
*
|
|
|
|
* Dedicated UDP sockets on the same
|
2014-03-02 09:31:40 +11:00
|
|
|
* machine can not be bound to in the
|
|
|
|
* traditional client/server method
|
2016-01-04 20:22:37 +11:00
|
|
|
*
|
2014-03-02 09:31:40 +11:00
|
|
|
* Every UDP socket is it's own UDP server
|
|
|
|
* And so must have a unique port on its
|
|
|
|
* machine, unlike TCP or Unix Sockts
|
|
|
|
* which can share on the same machine.
|
2016-01-04 20:22:37 +11:00
|
|
|
*
|
2014-03-02 09:31:40 +11:00
|
|
|
* Since there is no open client server
|
|
|
|
* relationship, you should start world
|
|
|
|
* first and then hello.
|
2016-01-04 20:22:37 +11:00
|
|
|
*
|
2014-08-28 12:09:01 +10:00
|
|
|
***************************************/
|
2014-02-22 20:13:31 +11:00
|
|
|
|
|
|
|
ipc.config.id = 'world';
|
|
|
|
ipc.config.retry= 1500;
|
|
|
|
|
2014-02-27 09:04:09 +11:00
|
|
|
ipc.serveNet(
|
|
|
|
'udp4',
|
2014-02-22 20:13:31 +11:00
|
|
|
function(){
|
2014-02-27 09:04:09 +11:00
|
|
|
console.log(123);
|
2014-02-22 20:13:31 +11:00
|
|
|
ipc.server.on(
|
|
|
|
'message',
|
|
|
|
function(data,socket){
|
2014-03-02 09:31:40 +11:00
|
|
|
ipc.log('got a message from '.debug, data.id.variable ,' : '.debug, data.message.data);
|
2014-02-27 09:04:09 +11:00
|
|
|
ipc.server.emit(
|
|
|
|
socket,
|
2014-02-22 20:13:31 +11:00
|
|
|
'message',
|
2014-02-27 09:04:09 +11:00
|
|
|
{
|
2014-03-02 09:31:40 +11:00
|
|
|
id : ipc.config.id,
|
2014-02-27 09:04:09 +11:00
|
|
|
message : data.message+' world!'
|
|
|
|
}
|
2014-02-22 20:13:31 +11:00
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-12-10 21:29:15 +11:00
|
|
|
|
2014-02-22 20:13:31 +11:00
|
|
|
|
2016-01-04 20:22:37 +11:00
|
|
|
ipc.server.start();
|