GithubHelp home page GithubHelp logo

udpp2p's Introduction

udpp2p

UDP hole punching service

Installation:

npm install udpp2p

Usage:

First, start up server that will try to establish connections between clients:

server = require("udpp2p").createServer({
  port: 1338 # listen on port 1338
})

server.start() # lift server

After that, there are two types of topologies between udp clients.

Centric topology

               ________ client1
              /
mainClient(host) ------ client2
              \________ client3

While using this type of service, you will need "host" client. everyone will then be connected right to him.

client = require("udpp2p").createClient({
  port: 1338
  host: "127.0.0.1"
  service: {
    name: "Service"
    type: "single" # when using swarm, use "swarm" instead of single
    host: true
  }
})

client.on "fail", (request, status, message) ->
  console.log "Request[#{request}] failed with status[#{status}] and message[#{message}]"

client.on "connect", (peer) ->
  console.log "Peer connected #{peer.host.private.address}:#{peer.host.private.port}"
  
  peer.send { ping: true }
  
client.on "disconnect", (peer) ->
  console.log "Peer disconnected #{peer.host.private.address}:#{peer.host.private.port}"

client.on "data", (peer, data) ->
  console.dir data

client.start()

Since host is not enough and you can't have more hosts centric topology, you will need clients:

client = require("udpp2p").createClient({
  port: 1338
  host: "127.0.0.1"
  service: {
    name: "Service"
    type: "single"
  }
})

# use same callbacks as in host

client.start()

Swarm topology ( everyone to everyone )

In this topology, every client is connected to every client. Because of that, all you need is clients.

client1 ------ client2
    \           /
     \         /
       client3

Example client:

client = require("udpp2p").createClient({
  port: 1338
  host: "127.0.0.1"
  service: {
    name: "Service"
    type: "swarm" # notice the swarm type of service
  }
})

# use same callbacks as in host

client.start()

udpp2p's People

Contributors

petomalina avatar

Stargazers

dooooooge avatar sharper avatar allen.hu avatar  avatar

Watchers

sharper avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.