Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simple bidirectional JSON message channels using net sockets.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 samples
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .npmignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 package.json
README.md

SimpleMessages

Simple bidirectional JSON message channels using net sockets.

Installation

Via npm on Node:

npm install simplemessages

Reference it from your program:

var simplemessages = require('simplemessages');

Usage

Server side

var server = simplemessages.createServer(function(channel) {
    channel.on('message', function(msg) {
        // each message process here
    });
});

server.listen(8000);

Sending a message (any Javascript value that can be processed by JSON.stringify

server.write(msg);

Client side, you specify port, host and, optionally, a callback on connect event:

var client = simplemessages.createClient(port, host, function() {
    // code to run at connect event
    client.write({ name: "my message" });
    // use client.write(msg) to send a message to the server    
    // when done, close the client channel
    client.end();
});

Alternatively, you can use a socket, and listen on it for connect event.

var socket = net.connect(port, host);
var client = simplemessages.createClient(socket);

// Launch on socket connect
socket.on('connect', function() {
    client.write({ name: "my message" });
    // use client.write(msg) to send a message to the server

    // when done, close the client channel
    client.end();
});

Development

git clone git://github.com/ajlopez/SimpleMessages.git
cd SimpleMessages
npm install
npm test

Samples

  • Broadcast Broadcast messages to all connected client.

Versions

  • 0.0.1: Published
  • 0.0.2: Published
  • 0.0.3: Published. Refactored to use ObjectStream
  • 0.0.4: Published. It uses ObjectStream 0.0.2
  • 0.0.5: Published. Engine range updated. It uses ObjectStream 0.0.3
  • 0.0.6: Published. Using ObjectStream 0.0.4

Contribution

Feel free to file issues and submit pull requests — contributions are welcome.

If you submit a pull request, please be sure to add or update corresponding test cases, and ensure that npm test continues to pass.

(Thanks to JSON5 by aseemk. This file is based on that project README.md).

Something went wrong with that request. Please try again.