node-ipc/spec/support/jasmineTest/UDP/udpSocketClient.spec.js

109 lines
3.4 KiB
JavaScript
Raw Normal View History

2016-01-10 20:03:05 +11:00
'use strict';
const ipc = require('../../../../node-ipc');
2016-01-10 18:23:40 +11:00
ipc.config.id ='testClient';
ipc.config.retry = 600;
describe(
2016-01-10 18:23:40 +11:00
'UDP Socket verification.',
function testDescription(){
2016-01-10 18:23:40 +11:00
it(
'Verify UDP server of type udp4 connects to UDP server named "udp4Server" and receives message.',
function testIt(done){
2016-01-10 18:23:40 +11:00
ipc.serveNet(
8001,
'udp4',
2016-01-10 20:30:30 +11:00
function serverStarted(){
ipc.server.on(
2016-01-10 18:23:40 +11:00
'message',
function gotMessage(data,socket){
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
}
);
ipc.server.emit(
{
address : 'localhost',
port : ipc.config.networkPort
},
2016-01-10 18:23:40 +11:00
'message',
{
id : ipc.config.id,
message : 'I am testClient'
}
2016-01-10 18:23:40 +11:00
);
ipc.server.on(
2016-01-10 18:23:40 +11:00
'error',
function(err){
2016-01-10 20:30:30 +11:00
expect(err).toBe(false);
testDone();
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();
}
);
it(
2016-01-10 18:23:40 +11:00
'Verify UDP server of type udp6 connects to UDP server named "udp6Server" and receives message.',
function(done){
2016-01-10 20:30:30 +11:00
ipc.config.networkPort=8099;
2016-01-10 18:23:40 +11:00
ipc.serveNet(
'::1',
8010,
'udp6',
function(){
ipc.server.on(
'message',
function(data,socket){
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 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 18:23:40 +11:00
ipc.server.on(
'error',
function(err){
2016-01-10 20:30:30 +11:00
expect(err).toBe(false);
testDone();
2016-01-10 18:23:40 +11:00
}
);
}
);
2016-01-10 20:30:30 +11:00
function testDone(){
ipc.server.stop();
}
2016-01-10 18:23:40 +11:00
ipc.server.start();
}
);
}
);