Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server #12

Open
amiiigh opened this issue Jun 28, 2019 · 8 comments
Open

Server #12

amiiigh opened this issue Jun 28, 2019 · 8 comments

Comments

@amiiigh
Copy link

amiiigh commented Jun 28, 2019

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?

@shovon
Copy link
Owner

shovon commented Jul 1, 2019

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.

@amiiigh
Copy link
Author

amiiigh commented Jul 1, 2019

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?

@shovon
Copy link
Owner

shovon commented Jul 1, 2019

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.

@amiiigh amiiigh closed this as completed Jul 1, 2019
@amiiigh amiiigh reopened this Jul 1, 2019
@amiiigh
Copy link
Author

amiiigh commented Jul 2, 2019

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.

@shovon
Copy link
Owner

shovon commented Jul 2, 2019

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.

@shovon
Copy link
Owner

shovon commented Jul 2, 2019

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

@shovon
Copy link
Owner

shovon commented Jul 2, 2019

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

@amiiigh
Copy link
Author

amiiigh commented Jul 3, 2019

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants