2016-01-10 23:32:46 +11:00
|
|
|
/*global describe, expect, it*/
|
2016-01-10 20:03:05 +11:00
|
|
|
|
2021-07-03 07:53:41 +10:00
|
|
|
const ipc = from '../../node-ipc');
|
2016-01-10 18:23:40 +11:00
|
|
|
|
2016-01-08 10:55:06 +11:00
|
|
|
describe(
|
2016-01-10 18:23:40 +11:00
|
|
|
'UDP Socket verification.',
|
2016-01-10 22:02:36 +11:00
|
|
|
function UDPSocketSpec(){
|
2016-01-10 18:23:40 +11:00
|
|
|
it(
|
|
|
|
'Verify UDP server of type udp4 connects to UDP server named "udp4Server" and receives message.',
|
2016-01-10 20:18:57 +11:00
|
|
|
function testIt(done){
|
2016-01-10 21:39:14 +11:00
|
|
|
ipc.config.networkPort=8095;
|
|
|
|
ipc.config.id ='testClient';
|
2016-09-30 23:00:28 +10:00
|
|
|
ipc.config.retry = 60;
|
2016-01-10 21:39:14 +11:00
|
|
|
|
|
|
|
let clientPort=8001;
|
|
|
|
|
2016-01-10 18:23:40 +11:00
|
|
|
ipc.serveNet(
|
2016-01-10 21:39:14 +11:00
|
|
|
clientPort,
|
2016-01-10 18:23:40 +11:00
|
|
|
'udp4',
|
2016-01-10 20:30:30 +11:00
|
|
|
function serverStarted(){
|
|
|
|
ipc.server.on(
|
2016-01-10 18:23:40 +11:00
|
|
|
'message',
|
2016-01-10 20:18:57 +11:00
|
|
|
function gotMessage(data,socket){
|
2016-01-11 00:10:48 +11:00
|
|
|
expect(socket).toBeDefined();
|
2016-01-10 18:23:40 +11:00
|
|
|
expect(data.id).toBe('udpServer');
|
|
|
|
expect(data.message).toBe('I am UDP4 server!');
|
2016-01-10 20:30:30 +11:00
|
|
|
testDone();
|
2016-01-10 18:23:40 +11:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-01-10 21:39:14 +11:00
|
|
|
ipc.server.on(
|
|
|
|
'error',
|
2016-01-10 22:02:36 +11:00
|
|
|
function gotErr(err){
|
2016-01-10 21:39:14 +11:00
|
|
|
expect(err).toBe(false);
|
|
|
|
testDone();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-01-10 20:18:57 +11:00
|
|
|
ipc.server.emit(
|
|
|
|
{
|
|
|
|
address : 'localhost',
|
|
|
|
port : ipc.config.networkPort
|
|
|
|
},
|
2016-01-10 18:23:40 +11:00
|
|
|
'message',
|
2016-01-10 20:18:57 +11:00
|
|
|
{
|
|
|
|
id : ipc.config.id,
|
|
|
|
message : 'I am testClient'
|
|
|
|
}
|
2016-01-10 18:23:40 +11:00
|
|
|
);
|
2016-01-10 21:39:14 +11:00
|
|
|
}
|
2016-01-10 18:23:40 +11:00
|
|
|
);
|
2016-01-10 20:30:30 +11:00
|
|
|
|
|
|
|
function testDone(){
|
|
|
|
ipc.server.stop();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
|
2016-01-10 18:23:40 +11:00
|
|
|
ipc.server.start();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-01-10 21:46:09 +11:00
|
|
|
it(
|
2016-01-10 18:23:40 +11:00
|
|
|
'Verify UDP server of type udp6 connects to UDP server named "udp6Server" and receives message.',
|
2016-01-10 23:57:08 +11:00
|
|
|
function testIt(done){
|
2016-01-10 20:30:30 +11:00
|
|
|
ipc.config.networkPort=8099;
|
2016-01-10 21:39:14 +11:00
|
|
|
ipc.config.id ='testClient';
|
2016-09-30 23:00:28 +10:00
|
|
|
ipc.config.retry = 60;
|
2016-01-10 21:39:14 +11:00
|
|
|
|
|
|
|
let clientPort=8010;
|
2016-01-10 18:23:40 +11:00
|
|
|
|
|
|
|
ipc.serveNet(
|
|
|
|
'::1',
|
2016-01-10 21:39:14 +11:00
|
|
|
clientPort,
|
2016-01-10 18:23:40 +11:00
|
|
|
'udp6',
|
2016-01-10 22:02:36 +11:00
|
|
|
function serverStarted(){
|
2016-01-10 18:23:40 +11:00
|
|
|
ipc.server.on(
|
|
|
|
'message',
|
2016-01-10 23:57:08 +11:00
|
|
|
function gotMessage(data,socket){
|
|
|
|
expect(socket).toBeDefined();
|
2016-01-10 18:23:40 +11:00
|
|
|
expect(data.id).toBe('udp6Server');
|
|
|
|
expect(data.message).toBe('I am UDP6 server!');
|
2016-01-10 20:30:30 +11:00
|
|
|
testDone();
|
2016-01-10 18:23:40 +11:00
|
|
|
}
|
2016-01-10 20:18:57 +11:00
|
|
|
);
|
2016-01-10 18:23:40 +11:00
|
|
|
|
2016-01-10 21:39:14 +11:00
|
|
|
ipc.server.on(
|
|
|
|
'error',
|
2016-01-10 22:02:36 +11:00
|
|
|
function gotErr(err){
|
2016-01-10 21:39:14 +11:00
|
|
|
expect(err).toBe(false);
|
|
|
|
testDone();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-01-10 18:23:40 +11:00
|
|
|
ipc.server.emit(
|
|
|
|
{
|
|
|
|
address : '::1',
|
2016-01-10 20:30:30 +11:00
|
|
|
port : ipc.config.networkPort
|
2016-01-10 18:23:40 +11:00
|
|
|
},
|
|
|
|
'message',
|
|
|
|
{
|
|
|
|
id : ipc.config.id,
|
|
|
|
message : 'I am testClient'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2016-01-10 20:30:30 +11:00
|
|
|
|
|
|
|
function testDone(){
|
|
|
|
ipc.server.stop();
|
2016-01-10 21:39:14 +11:00
|
|
|
done();
|
2016-01-10 20:30:30 +11:00
|
|
|
}
|
|
|
|
|
2016-01-10 18:23:40 +11:00
|
|
|
ipc.server.start();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|