-
Notifications
You must be signed in to change notification settings - Fork 10
External API
Ivanq edited this page May 29, 2018
·
3 revisions
Broadcasts a message to all the network.
Arguments:
-
message
- the string/object/anything you want to broadcast. -
privatekey=None
- how to sign the message (see below). -
peer_count=5
- the count of peers to connect to. -
immediate=False
- if True and the browser is closed, the message will be saved in memory and flushed to browser when the site is opened.
Send message to one IP.
-
ip
- IP to send the message to. -
message
- data to send. -
privatekey=None
- how to sign the message (see below). -
to=None
- reply to. (see below for example) -
immediate=False
- same as inpeerBroadcast
(read above).
It's quite difficult to get peer IP. It's recommended to use this method only if you know the real IP - from whatismyipaddress service or IPX (huh, that's defenitely NOT what you thought about).
// Send message to IP
let IP = "1.2.3.4:5";
zeroFrame.cmd("peerSend", {ip: IP, message: "ping"}, function(result) {
console.log("Received", result.message);
});
zeroFrame.onRequest = function(cmd, message) {
if(cmd == "peerReceive") {
// Validate message. Read below
zeroFrame.cmd("peerValid", [message.params.hash]);
let fromIP = message.params.ip; // That's where we got the message from
let fromHash = message.params.hash; // That's the ID of the message
zeroFrame.cmd("peerSend", {ip: fromIP, to: fromHash, message: "pong"}); // Reply
}
};
Sets the message as invalid or valid. Valid messages are broadcast to other peers, those who send invalid messages are banned.
Arguments:
-
hash
- the hash of the message you received.
Always. No - ALWAYS run peerInvalid
and peerValid
. NEVER forget it, or messages won't be broadcast.