node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org »


Prescription Net

This exposes the core node.js net module as a set of functions that return Prescription FRP Observables instead of taking callbacks.


Echo server:

var net = require("prescription-net");
// Create a server instance 
var server = new net.Server();
// Make the server listen on port 3000, we're only interested in the connection 
// Observable, so we subscribe() that one through and we subscribe to each of 
// the sockets it's emit back to themselves (echo server) 
server.listen(3000).connection.subscribe(function(observables) {

TCP client:

var net         = require("prescription-net");
var client      = new net.Socket();
var observables = client.connect(3000);
var connect     = observables.connect;
var socket      = observables.socket; {
    return data.toString();
}).subscribe(function(data) {
connect.subscribe(function() {
    socket.onNext("beep bop boop");