anternet-streamer

0.0.0 • Public • Published

anternet-streamer.js

build npm Join the chat at https://gitter.im/Anternet/anternet.js npm

Anternet library for streaming large data chunks over UDP protocol.

Example File Server

const fs = require('fs');
const Anternet = require('anternet');
const Streamer = require('anternet-streamer');
const Source = Streamer.Source;
 
const anternet = new Anternet();
const streamer = new Streamer(anternet);
 
const msgType = 1001; // custom message type
 
// service files on `msgType`
anternet.on(msgType, (rid, args, rinfo) => {
  const filePath = args[0];
  
  // create a new source only if not exists already
  const source = streammer.get(filePath, path => Source.fromFile(path));
  
  // create a private referance for this peer
  const ref = streammer.stream(source, rinfo.port, rinfo.address, {start: 10, end: 8000});
 
  // send the referance back to the peer
  anternet.response(rid, [ref], rinfo.port, rinfo.address);
});
 
// other peer address
const address = '127.0.0.1';
const port = 12345;
 
// request "foo.js" from other peer
anternet.request(msgType, ['foo.js'], port, address, (err, args, rinfo) => {
  if (err) throw err;
 
  const ref = args[0];
  streammer.read(ref, port, address).pipe(process.stdout);
});

License

MIT License. Copyright © 2016 Moshe Simantov

Package Sidebar

Install

npm i anternet-streamer

Weekly Downloads

1

Version

0.0.0

License

MIT

Last publish

Collaborators

  • moshe