Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple Bitcoin like server with central/miner server #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rfc-1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
walletServer/node_modules
minerServer/node_modules
centralServer/node_modules
28 changes: 28 additions & 0 deletions rfc-1/centralServer/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// centralServer.js
const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 8080 });

let miners = [];

wss.on('connection', (ws) => {
miners.push(ws);
console.log('Miner connected');

ws.on('message', (message) => {
console.log('Received:', message);

miners.forEach((miner) => {
if (miner !== ws && miner.readyState === WebSocket.OPEN) {
miner.send(message);
}
});
});

ws.on('close', () => {
miners = miners.filter((miner) => miner !== ws);
console.log('Miner disconnected');
});
});

console.log('Central server running on ws://localhost:8080');
Loading