tubing
Tubing in a modular socket library that uses the same client/server code regardless of transport.
High Level Idea
There are two main concepts which are goals of this project.
First, to decouple the creation of a socket from the operation of the socket itself. This is achieved through the acceptor-connector pattern (though I call them listeners and connectors).
Second, to allow for modular "protocols" to be easily built on top of the connections
created by tubing
. This would be things like RPCs, pub/sub, or any custom application
protocol you might need. Protocols can also add middleware to achieve things like
encryption or authentication.
Example
The nice thing about tubing is that you write your client and server the same way, regardless
of the underlying transport. The only change is usually the line of code that calls
connect
or listen
.
Server
;;; const rpcHandlers = { return value; } { return { ; }; } // create the tubing appconst app = ; // add an rpc protocolapp; // create a websocket server and listen on port 3000;
Client
;;; // create the tubing appconst app = ; // add an rpc protocolapp; // when a new socket is created, make some rpc callsapp; // connect to a websocket server on localhost port 3000;