-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathp2p.js
27 lines (26 loc) · 965 Bytes
/
p2p.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
const crypto = require("crypto"),SHA256 = message=>crypto.createHash("sha256").update(message).digest("hex");
const EC = require("elliptic").ec,ec = new EC("secp256k1");
const {Block,Blockchain,Transaction,myChain} = require("./block.js")
const MINT_PRIVATE_ADDRESS = ""
// Import the package
const WS = require("ws");
// Create a server
const server = new WS.Server({ port: "8080" });
// Listens for connections
server.on("connection", async (socket, req) => {
// This event handler will be triggered every time somebody send us connections
});
// Get the socket from an address
const socket = new WS("SOME ADDRESS");
// Open a connection
socket.on("open", () => {
// This event handler will be triggered when a connection is opened
})
// Close a connection
socket.on("close", () => {
// This event handler will be triggered when the connection is closed
})
// Listens for messages
socket.on("message", message => {
// "message" is message, yes
})