forked from nodejs/node-v0.x-archive
-
Notifications
You must be signed in to change notification settings - Fork 25
An introduction to run http over udp with node.js
tomzhou edited this page Nov 18, 2020
·
3 revisions
-
API is compatible to HTTP. Just require('httpp') instead of http, when you coding.
-
The HTTPP to HTTP modules mapping is like below: net -> udt, http -> httpp, tls -> udts, https -> httpps.
echo_srv.js:
var udt = require('udt');
var srv = udt.createServer(function(socket){
socket.pipe(socket);
});
srv.listen(51686);
console.log('Listening on UDP port 51686');
echo_cln.js
var udt = require('udt');
var cln = udt.connect({port:51686} , function(){
console.log('you can type char here, then server send it back:\n');
process.stdin.resume();
process.stdin.pipe(cln);
cln.pipe(process.stdout);
});
httpp_srv.js
var httpp = require('httpp');
var srv = httpp.createServer(function(req, res){
res.end('Hi, just say hi to you over UDP ...\n');
});
srv.listen(51688);
console.log('HTTPP server listing on UDP port 51688');
httpp_cln.js
var httpp = require('httpp');
httpp.get('http://localhost:51688', function(res){
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});