1 /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 var assert = require('assert');
17 var dgram = require('dgram');
23 var server = dgram.createSocket('udp4');
25 server.on('error', function(err) {
30 server.on('message', function(data, rinfo) {
31 console.log('server got data : ' + data);
34 server.send(data, rinfo.port, 'localhost', function (err, len) {
36 if (sendcount >= sockcount) {
44 for (var i = 0; i < sockcount; i++) {
45 (function sendAndRecieve(i) {
46 var client = dgram.createSocket('udp4');
48 client.send(i.toString(), port, 'localhost');
50 client.on('error', function(err) {
55 client.on('message', function(data, rinfo) {
56 console.log('client got data : ' + data);
57 assert.equal(port, rinfo.port);
58 assert.equal(data, i.toString());
64 process.on('exit', function(code) {
65 assert.equal(msg.length, sockcount);
66 for (var i = 0; i < sockcount; i++) {
67 if (msg.indexOf(i.toString()) == -1) {
71 assert.equal(code, 0);