Newly Practicing Mortician

    socket.io-reqres

    0.0.9 • Public • Published

    Request/response for socket.io

    Emulates request/response pattern in socket.io. You can also choose to make your Node.js app a client, and make browser a server.

    On "client" side:

    var Client = require("socket.io-reqres").Client;
    var client = new Client;
     
    // Where `socket` is socket.io socket object.
    client.setSocket(socket);
     
    client.request("myMethod", "Hello", function(err, response) {
        console.log(err, response);
    });

    On "server" side:

    var Server = require("socket.io-reqres").Server;
     
    var server = new Server;
    server.use("myMethod", function(data, send) {
        send(data + " world");
    });
     
    // Where `socket` is socket.io socket object.
    server.setSocket(socket);

    API

    • new Server(name) - optional server name, defaults to "".
    • Server.setSocket(socket) - set socket.io socket object.
    • Server.use(method, callback) - register RPC method.
    • new Client(name, timeout) - optional server name, defaults to "". Optional timeout in ms.
    • Client.setSocket(socket) - set socket.io socket object.
    • Client.request(method, data, callback) - send request to the server.

    Keywords

    none

    Install

    npm i socket.io-reqres

    DownloadsWeekly Downloads

    0

    Version

    0.0.9

    License

    none

    Last publish

    Collaborators

    • streamich