package
Simple bidirectional JSON message channels using net sockets as object streams
npm install simplemessagesGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 2 packages.
28.5 kB
Includes dependencies.
Simple bidirectional JSON message channels using net sockets.
Via npm on Node:
npm install simplemessagesReference it from your program:
var simplemessages = require('simplemessages');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();
});
git clone git://github.com/ajlopez/SimpleMessages.git
cd SimpleMessages
npm install
npm testFeel 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).