0.0.11 • Published 9 years ago

avs-proxy v0.0.11

Weekly downloads
-
License
MIT
Repository
-
Last release
9 years ago

proxy

Proxy for avs-rpc.

The proxy connects clients and servers through ioRpc (cf. avs-rpc). This allows servers to be distributed on various machines without clients having to know their location. It is particularly useful when servers are behind routers (NAT).

Clients connect to the proxy and use the services published by the servers.

Install

npm install avs-rpc
npm install avs-proxy

In browser:

<script src=".../avs-proxy.min.js"></script>

Start proxy

node proxy.js 4241

where 4241 is the server listening port

proxy server

A proxy server publishes one domain (service). For this domain, a rpc object will be instantiated upon client connection. This rpc object implements the methods that need to be available to the client through the avs-rpc mechanism.

proxy = require('avs-proxy');

function getUserProfile(name) { return {name:'test', age:32}; }
var local = {};
local.getUserProfile = getUserProfile;

new proxy.Server("http://localhost:4241", 'mydomain', function(rpc, err) {
    rpc.implement(local); 
});

An error is returned if the domain is already registered on the proxy.

proxy client

A proxy client connects to the proxy indicating via the URL the domain it needs to subscribe to. Once connected, the client can use any of the remote methods published in the domain subscribed.

proxy = require('avs-proxy');

new proxy.Client("http://localhost:4241/mydomain", function(rpc, err) {
    if (err) { console.log(err); } 
    else {
        var remote = rpc.remote('getUserProfile');
        remote.getUserProfile('test', function(msg, err) {
            if (err) { console.log(err); } 
            else { console.log("getUserProfile: " + msg.age); }
        });
    }
});

Browser

The UMD bundle name of the minified library is proxy. The example below shows how to use a proxy client in the browser.

Example:

new proxy.Client('http://localhost:4241/mydomain', function(rpc, err) { ... 
...

License

The MIT License (MIT)

Copyright (c) 2014 gigerlin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago