Coder Social home page Coder Social logo

jschan-ws's Introduction

jschan websocket transport   Build Status

jschan is a JavaScript port of libchan based around node streams

Find out more about jschan

Install

npm install jschan-ws --save

ws.clientSession(url)

Creates a new websocket session. The url can be in the form 'ws://localhost' or passes as an object. It is based on streamSession.

ws.clientSession is not compatible with libchan.

This method can also work in the browser thanks to Browserify.

Example:

var websocket = require('jschan-ws');
var session = websocket.clientSession('ws://localhost:3000');
var chan    = session.WriteChannel();
var ret     = chan.ReadChannel();

ret.on('data', function(res) {
  console.log(res);
  session.close();
});

chan.end({
  hello:'world',
  returnChannel: ret
});

websocket.server(options)

Creates a new websocketServer, or attach the websocket handler to the passed-through httpServer object. It is based on streamSession.

websocket.server is not compatible with libchan.

If a new http server is created, remeber to call listen, like so:

'use strict';

var websocket = require('jschan-ws');
var server = websocket.server();

function handleMsg(msg) {
  var stream = msg.returnChannel;
  delete msg.returnChannel;
  stream.end(msg);
}

function handleChannel(chan) {
  chan.on('data', handleMsg);
}

function handleSession(session) {
  session.on('channel', handleChannel);
}

server.on('session', handleSession);

server.listen(3000);

About LibChan

It's most unique characteristic is that it replicates the semantics of go channels across network connections, while allowing for nested channels to be transferred in messages. This would let you to do things like attach a reference to a remote file on an HTTP response, that could be opened on the client side for reading or writing.

The protocol uses SPDY as it's default transport with MSGPACK as it's default serialization format. Both are able to be switched out, with http1+websockets and protobuf fallbacks planned. SPDY is encrypted over TLS by default.

While the RequestResponse pattern is the primary focus, Asynchronous Message Passing is still possible, due to the low level nature of the protocol.

Graft

The Graft project is formed to explore the possibilities of a web where servers and clients are able to communicate freely through a microservices architecture.

"instead of pretending everything is a local function even over the network (which turned out to be a bad idea), what if we did it the other way around? Pretend your components are communicating over a network even when they aren't." Solomon Hykes (of Docker fame) on LibChan - [link]

Find out more about Graft

Contributors

License

MIT

jschan-ws's People

Contributors

adrianrossouw avatar

Stargazers

Michael Anthony avatar Chris Hart avatar

Watchers

Matteo Collina avatar  avatar James Cloos avatar Michael Anthony avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.