npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pingpong

v1.0.1

Published

Dead simple RPC with response support

Downloads

5

Readme

pingpong.js

Dead simple RPC with response support.

Build Status

Install on Node

npm install pingpong

What it does

Allows a client side function to invoke a server side function with some arguments and an optional callback. The server can use the callback to send a reply or an error to the client.

Usage

Server:

var pingpong = require('pingpong');

pingpong.server(8000, function (err, server) {

  server.onConnect(function (client) {
    client.onMessage(function (text, responder) {
      responder(null, text.toUpperCase());
    });
  });

});

Client:

var pingpong = require('pingpong');

pingpong.client({ port : 8000 }, function (err, remote) {
  remote.invoke('Hello world!', function (err, result) {
    console.log(result);
  });
});

Prints HELLO WORLD!.

Run echo.sh from within the examples directory to see it in action.

API

  • server(port, callback): Creates a server. Invokes callback with (err, server).
  • client(config, callback): Creates a new client. The config is passed to net.connect. Invokes callback with (err, remote).
  • bind(socket, handler): Binds a message handler to the given socket and returns an invoker. The message handler will receive messages and invoker can be used to invoke functions on the other side.

Server API

  • server: The server returned by net.createServer.
  • clients: An array of clients.
  • onConnect(callback): Sets the connection handler. On new client connections, callback is invoked with client.
  • onDisconnect(callback): Sets the disconnct handler. On client disconnects, callback is invoked with client.

Server side client API

  • socket: The net.Socket of the client.
  • onMessage(callback): Sets the client message handler. On new client messages, callback is invoked with the arguments that where passed in on the client side. If a client passes in a callback as the last argument to invoke, it is passed in to the handler and allows to send a reply.
  • invoke(...[, callback]): Invokes the onMessage callback of thie client with the given arguments. If a callback is given, it will be invoked with (err, reply).

Client side remote API

  • socket: The socket as returned by net.connect.
  • invoke(...[, callback]): Invokes the onMessage callback for this client on the server with the given arguments. If a callback is given, it will be invoked with (err, reply).
  • onMessage(callback): Sets the server message handler. On new server messages, calback is invoked with the arguments that where passed in on the server side. If a server passes in a callback as the last argument to invoke, it is passe in to hte handler and allows to send a reply.

Compatibility

Node 0.10, 0.12

License

MIT