New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

udp2p

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

udp2p

P2P connection with UDP hole punching

0.2.17
latest
Source
npm
Version published
Weekly downloads
14
366.67%
Maintainers
1
Weekly downloads
 
Created
Source

UDP2P

P2P connection with UDP hole punching

Install

npm install udp2p

Quick start

var udp2p = require('udp2p');
var client = new udp2p();

client.connect(function () {
  client.fetchClient(function(e, d) {
    d.map(function(v) {
      var c = v.name;
      client.peerMsg({message: 'Hello, ' + c}, c, function (ee, dd) {});
    })
  });
});

Provides hole punching services (Server Mode)

var udp2p = require('udp2p');
var tracker = {
  address: 'tracker.cc-wei.com',
  port: 2266
};
var options = {
  server: true,
  port: 2266,
  tracker: [tracker]
};

var server = new udp2p(options);

Connect with hole punching server (Client Mode)

var udp2p = require('udp2p');
var client = new udp2p();
var server = {
  address: 'tracker.cc-wei.com',
  port: 2266
};

client.connect(server, function(err) {
  console.log("status:", client.getStatus());
});

Fetch client list

client.fetchClient(function(err, list) {
  console.log(list);
});

Send message

var message = {
  message: 'Hello UDP2P!'
};

var peer = client.getClientList().pop().name;
client.peerMsg(message, peer, function(err, response) {});

Send file

var filepath = '/Users/luphia/Documents/Workspace/Playground/logo.png';
var peer = client.getClientList().pop().name;
client.peerFile(filepath, peer, function(err, response) {});

Setup event

var savePath = '/Users/luphia/Desktop/';

client.on('message', function (data) {
  console.log('%s: %s', data.from, JSON.stringify(data.content));
});

client.on('file', function (data) {
  console.log('recieve file [%s] from %s', data.from, data.name);
  data.r2x.save(savePath + data.name);
});

Setup Reaaction

client.on('message', function (d) {
  var file = d.content.file;
  if(file) {
    console.log(file);
    client.response(file, d);
  }
  else {
    console.log(d);
  }
});

Request a file

var filepath = '/Users/luphia/Desktop/upload/crownfond.png';
client.request({file: filepath}, 'client2', function (d) {console.log('Response'); console.log(d);});

Keywords

p2p

FAQs

Package last updated on 14 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts