Open amiiigh opened 5 years ago
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.
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?
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.
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.
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.
Connection
into a stream.Duplex
Stretch goal: maintain TypeScript types.
@amiiigh let me know if you are still interested in doing so.
Please pull from master. I've made some changes, recently.
@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!
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?