Giter Club home page Giter Club logo

node-rudp's Introduction

rudp

Reliable UDP implementation for Node.js.

Example

For a peer-to-peer application, you can write a script like this:

var rudp = require('rudp');
var dgram = require('dgram');

var socket = dgram.createSocket('udp4');

socket.bind(localPort);

var client = new rudp.Client(socket, remoteAddress, remotePort);

// And do whatever you want here

node-rudp's People

Contributors

mvayngrib avatar shovon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-rudp's Issues

getting the remote info on message

Hi,

I'm trying to use the Server and my problem is as part of the dgram.socket I can use 'message' listener to get 'data' and 'remote' which contains source address and port of the sender.

How can I get this information using this library?

callback for send

would be nice to be able to do something like this:

client.send(data, function() {
// the packets this data was split up into have all been acknowledged
})

PendingPacket keeps going after client.close()

thanks for the great lib!

here's the breaking test:

var rudp = require('rudp');
var dgram = require('dgram');

var billSocket = dgram.createSocket('udp4');
var tedSocket = dgram.createSocket('udp4');
billSocket.bind(function() {
  tedSocket.bind(function() {
    var billClient = new rudp.Client(billSocket, '127.0.0.1', tedSocket.address().port);
    var tedClient = new rudp.Client(tedSocket, '127.0.0.1', billSocket.address().port);
    tedClient.on('data', function(data) {
      billClient.close()
      tedClient.close()
    })

    billClient.send(new Buffer('excellent!'))
  })
})

and here's the error stack trace:

dgram.js:439
    throw new Error('Not running'); // error message from dgram_legacy.js
          ^
Error: Not running
    at Socket._healthCheck (dgram.js:439:11)
    at Socket.send (dgram.js:282:8)
    at PacketSender.send (/Users/tenaciousmv/Code/node-rudp/lib/PacketSender.js:13:16)
    at null.<anonymous> (/Users/tenaciousmv/Code/node-rudp/lib/PendingPacket.js:23:24)
    at wrapper [as _onTimeout] (timers.js:287:14)
    at Timer.listOnTimeout (timers.js:133:15)

getting corrupted data in one end point

Heyyy it's me again :D

So I have a new problem.
The thing is I encrypt my data before sending it to my client and the client has to decrypt the data obviously! So I add some data before the real data as a header and I validate the header on the client. So if I couldn't read the header correctly that means there is something wrong with the data.

which is happening when I'm using the library. Should I split the data before sending it? Is there something that I'm missing here?
How should I approach this problem?

How would the library react if packets received unordered?

Thanks <3

How does this work for clients behind NATs?

Does this use some form of UDP hole punching? If so, then wouldn't this require a separately hosted rendezvous server? If this isn't the method used could you give a high level overview of what is happening? Thanks.

emit event on receipt of all packets in a "message"

When A sends a msg M to B, B should be able to know when it's received the entire message M (as opposed to 'data', which is a fragment of M).

From a usage perspective, maybe something like:

a.send(aLongMessage)
b.on('message', function (msg) {
//  msg === aLongMessage
})

msg not rebuild?

there is a test from your example,
when msg greater than 512,it will splite to some mini msg(512)
and not rebuild in other peer.

var gobackn = require('../../lib');
var dgram = require('dgram');

var serverSocket = dgram.createSocket('udp4');
var clientSocket = dgram.createSocket('udp4');

serverSocket.bind(3001);

console.log('Bound the server socket to port 3001');

var server = new gobackn.Server(serverSocket);
var client = new gobackn.Client(clientSocket, '127.0.0.1', 3001);

server.on('close', function () {
serverSocket.close();
});

client.on('close', function () {
clientSocket.close();
});

server.on('connection', function (connection) {
connection.on('data', function (data) {
console.log('data:' + data.toString('utf8'));
});

connection.send(new Buffer('Hello, Client!'));
});

client.on('data', function (data) {
console.log('Client: %s', data.toString('utf8'));
});

var info = '';
for(var i = 0; i < 16*1024; i ++)
info += ' ' + i;

client.send(new Buffer('Hello, World!'));
client.send(new Buffer('How are you doing?'));
client.send(new Buffer(info));

Server

Hey,
Would you please also provide an example for the Server part?

How can I get the data after the server received any? shouldn't be a listener on connection and emit the data after?

buffertools

Hey,
I don't think it's an issue with this repo but it seems like I can't use buffertools in my project. I'm getting an error saying undefined symbol or something. Can I use Buffer.compare instead of buffertools?

More specific working example

I have spent some hours trying to get this thing to work, without success. Tried to set up the file sharing example, and add some console.logs to understand where it goes wrong.

Here is my setup. And the output from the processes. Everyone is run on separate machines, but client and server are behind the same NAT.

Mediator

# node mediator.js -p 5000
Registered a0af11ac, from host 194.140.150.160

Server

# node app.js -m 194.142.159.165:5000 -f ~/Documents/test.txt
Requesting to register a0af11ac
Got request to talk to remote host at 194.140.150.160, 51036
Sending the file /home/akaustel/Documents/test.txt 1588 bytes (sending 1596 bytes)

Client

# node app.js -m 194.142.159.165:5000 -t a0af11ac
Requesting to talk to a0af11ac
Got request to talk to remote host at 194.140.150.160, 48317
Just waiting on a file.

I would be very happy to get some pointers to get this working!

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.