-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmine-server.js
38 lines (30 loc) · 1.15 KB
/
mine-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const net = require('net');
// Mockup of a function to simulate Keccak hashing
function simulateKeccakHash(input) {
// Simulated hash function implementation
return "0000" + Math.random().toString(16).slice(2, 66); // Simulate 256-bit hash output with leading zeros
}
// Create a TCP server
const server = net.createServer((socket) => {
console.log('Client connected:', socket.remoteAddress, socket.remotePort);
// Handle data from the client
socket.on('data', (data) => {
console.log('Received data from client:', data.toString());
// Simulate Keccak hashing
const hash = simulateKeccakHash(data.toString());
// Echo the hash back to the client
socket.write(hash);
});
// Handle client disconnection
socket.on('end', () => {
console.log('Client disconnected:', socket.remoteAddress, socket.remotePort);
});
// Handle errors
socket.on('error', (err) => {
console.error('Socket error:', err);
});
});
// Start the server and listen on port 8080
server.listen(8080, () => {
console.log('Server listening on port 8080');
});