n2n icon indicating copy to clipboard operation
n2n copied to clipboard

Unable to send messages through the network

Open breadbored opened this issue 10 years ago • 1 comments

We are able to make a connection to the network, show when people connect, disconnect, and who all is online.

Here is what we have to show for it:

var Node = require('n2n').Node;
var node = new Node(5146);

console.log("Connecting to the network...\n\n\n");
node.connect([{ host: 'bradleypl.us', port: 5146 }]);

node.on('online', function () {
  console.log('Your ID:', this.id);
  console.log('Online ids:', node.sortedIds);
});

//just for testing, this will spam the terminal if repeated every time.
node.on('node::online', function (newNode) {
  console.log('Someone is online:', newNode.id);
});

//just for testing, this will spam the terminal if repeated every time.
node.on('node::offline', function () {
  console.log('Someone just left!');
});

This is where we have no idea what to so. Now how does one send messages? We can see something like:

node.broadcast("node::test","message");

Being used to send a "node::test" event to everyone on the network. That is then received with:

node.on("node::test", function (message) {
  console.log("New message:",message);
}

But that doesn't work... Any idea?

breadbored avatar Feb 15 '15 14:02 breadbored

Try node.broadcast("test","message"); and on the receive event fnct node.on("node::test", function (senderID,message) { console.log("New message:",message); }

vroomDotClub avatar Jul 07 '17 19:07 vroomDotClub