gracenode-udp

0.1.1 • Public • Published

gracenode-udp Module

UDP Module for gracenode framework.

This is designed to function within gracenode framework.

How to include it in my project

To add this package as your gracenode module, add the following to your package.json:

"dependencies": {
    "gracenode": "",
    "gracenode-udp": ""
}

To use this module in your application, add the following to your gracenode bootstrap code:

var gracenode = require('gracenode');
// this tells gracenode to load the module
gracenode.use('gracenode-udp');

To access the module:

// the prefix gracenode- will be removed automatically
gracenode.udp

Access

gracenode.udp

Configurations

"modules": {
    "udp": {
        "servers": [
            { name: "unique name for server", "host": "host name or IP", "port": port number }[...]
        ],
        "requests": {
            "unique request name": { "host": "host name or IP", "port": port number }
        }
    }
}
API: startServers
void startServers(Function callback)

Starts all UDP servers and calls the callback function when all the servers are up

API: getServerByName
Object getServerByName(String serverName)

Returns a server object by a server name defined in the configurations

startServer MUST be called before invoking this function

Example

var server = gracenode.udp.getServerByName('server');
 
// handle UDP message requests
server.on('message', function (messageBuffer, requestObj) {
    // do something
});
 
// handle error
server.on('error', function (error) {
    // handle error
});
API: send
void send(String requestName, Mixed message, Object options, Function callback)

Sends a UDP packet message to destination named in the configurations

The callback returns error as the first argument and bytes sent as the second argument

Package Sidebar

Install

npm i gracenode-udp

Weekly Downloads

0

Version

0.1.1

License

MIT

Last publish

Collaborators

  • voltrue2