Skip to content
Snippets Groups Projects
Commit e90f064e authored by arshiam2's avatar arshiam2
Browse files

init

parent d87c80b3
No related branches found
No related tags found
No related merge requests found
Pipeline #40682 failed
*
!index.js
!package.json
!yarn.lockxw
\ No newline at end of file
node_modules
\ No newline at end of file
FROM mhart/alpine-node:10 as base
WORKDIR /usr/src
COPY package.json yarn.lock ./
RUN yarn --production
FROM mhart/alpine-node:base-10
WORKDIR /usr/src
COPY --from=base /usr/src .
COPY . .
CMD node index.js
EXPOSE 20000:20000/udp
index.js 0 → 100644
const PORT = 20000;
const MULTICAST_ADDR = "233.255.255.255";
const dgram = require("dgram");
const process = require("process");
const socket = dgram.createSocket({ type: "udp4", reuseAddr: true });
socket.bind(PORT);
socket.on("listening", function() {
socket.addMembership(MULTICAST_ADDR);
socket.setBroadcast(true)
setInterval(sendMessage, 2500);
const address = socket.address();
console.log(
`UDP socket listening on ${address.address}:${address.port} pid: ${
process.pid
}`
);
});
function sendMessage() {
const message = Buffer.from(`docker ${process.pid}`);
socket.send(message, 0, message.length, PORT, MULTICAST_ADDR, function() {
// console.info(`Sending message "${message}"`);
});
}
socket.on("message", function(message, rinfo) {
console.info(`Message from: ${rinfo.address}:${rinfo.port} - ${message}`);
});
\ No newline at end of file
{
"name": "membership-client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "node test.js"
},
"author": "Aria <arshiam2828@gmail.com>",
"license": "MIT",
"dependencies": {
"dgram": "^1.0.1"
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
dgram@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/dgram/-/dgram-1.0.1.tgz#37f3b200f8033a5ff759303089c81ce361b651c3"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment