Giter VIP home page Giter VIP logo

Comments (8)

shovon avatar shovon commented on June 16, 2024 1

Correct me if I'm wrong, so the 'Server' and 'Connection' are an EventEmitter but not a Stream. I can't find write function for Connection in its file.

You are right. It is not a stream. I will need to implement the stream functionality.

Also can the server reply to the client by just using that connection, with something like connection.send() or connection.write() ?

Yes. With connection.send.

My last question is about net.socket.end() function in net library in node. Is there anything equivalent to that in this library?

This library is a wrapper for the dgram library. So just call close on the initial UDP socket that is being wrapped.

from node-rudp.

shovon avatar shovon commented on June 16, 2024

HI @amiiigh. I'll be on it. I'll document on how to use this library.

In the meanwhile, this is how you use the library for the purposes of using it like a server.

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

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

// Where `localPort` is the port to connect to.
socket.bind(localPort);

var server = new rudp.Server(socket);

server.on('connection', socket => {
  socket.on('data', data => {
    console.log(data.toString('utf8'));
  });
  socket.write('Hello, World!');
});

Essentially, it is used like Node.js' net library, when creating a server.

from node-rudp.

amiiigh avatar amiiigh commented on June 16, 2024

Hey @shovon
Thanks for the example

I'm just a bit confused now.
Correct me if I'm wrong, so the 'Server' and 'Connection' are an EventEmitter but not a Stream. I can't find write function for Connection in its file.
Eventually, I want to pipe the connection data to another stream to handle uplink and downlink limit on my application so I think I need them to be a Stream, am I right?

Also can the server reply to the client by just using that connection, with something like connection.send() or connection.write() ?

My last question is about net.socket.end() function in net library in node. Is there anything equivalent to that in this library?

from node-rudp.

amiiigh avatar amiiigh commented on June 16, 2024

Hey, @shovon it's me again :D
I'm trying to make the connection class like net.socket so my understanding is I need to make connection a Duplex stream, am I right?
For doing that I just need to implement a couple of functions like _write and _read _final.

Do I need to modify any other part of the code?

for the _write function it's just going to call the send function, right?

Also, do you have any plan to make your library for es6? I can help if you like to do that.

from node-rudp.

shovon avatar shovon commented on June 16, 2024

I am more than thankful that you want to look into helping me turn Connection into Node.js' stream.Duplex, as well as translate the code into ES6.

So here are the steps that we want to do in order to achieve the above.

  1. convert Connection into a stream.Duplex
  2. translate the code into ES6

Stretch goal: maintain TypeScript types.

from node-rudp.

shovon avatar shovon commented on June 16, 2024

@amiiigh let me know if you are still interested in doing so.

from node-rudp.

shovon avatar shovon commented on June 16, 2024

Please pull from master. I've made some changes, recently.

from node-rudp.

amiiigh avatar amiiigh commented on June 16, 2024

@amiiigh let me know if you are still interested in doing so.

yeah man, let's do it!

Please pull from master. I've made some changes, recently.
okay!

from node-rudp.

Related Issues (12)

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.