Comments (8)
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.
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.
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.
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.
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.
- convert
Connection
into astream.Duplex
- translate the code into ES6
Stretch goal: maintain TypeScript types.
from node-rudp.
@amiiigh let me know if you are still interested in doing so.
from node-rudp.
Please pull from master. I've made some changes, recently.
from node-rudp.
@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)
- More specific working example HOT 6
- PendingPacket keeps going after client.close()
- callback for send HOT 5
- Turn `rudp` into a streaming library HOT 3
- validate packets - not all may be meant for the client HOT 6
- emit event on receipt of all packets in a "message"
- How does this work for clients behind NATs? HOT 8
- buffertools HOT 2
- getting the remote info on message HOT 1
- getting corrupted data in one end point HOT 5
- msg not rebuild?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-rudp.