Socket
Book a DemoInstallSign in
Socket

request-stream

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-stream

json request-response over a stream

Source
npmnpm
Version
0.1.1
Version published
Weekly downloads
287
42.79%
Maintainers
1
Weekly downloads
 
Created
Source

Request-Stream

Request-Stream is a stream implementing a JSON request and response protocol

npm install request-stream

Lets try to setup a simple server

var rs = require('request-stream');
var net = require('net');

net.createServer(function(socket) {
	var r = rs();

	socket.pipe(r).pipe(socket);

	r.on('request', function(request, respond) {
		respond(null, {echo:request});
	});
}).listen(9000);

To make a request to the server we need to create a socket to the server and pipe our request to that.

var socket = net.connect(9000);
var r = rs();

socket.pipe(r).pipe(socket);

r.request('echo me please', function(err, reply) {
	console.log(err, reply);
});

If we wanted to use tls instead of tcp we could just have implemented the above example using tls streams. We could even use WebSockets using shoe.

Keywords

stream

FAQs

Package last updated on 18 Nov 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts