Skip to content

A simplified regacy win32 DDE wrapper for node.js

License

Notifications You must be signed in to change notification settings

iblislin/node-dde

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node-dde

Node-dde is a simplified regacy win32 Dynamic Data Exchange (DDE) wrapper for node.js using Edge.js and NDde. The client listen to the asynchronous advise on multi-threaded CLR without blocking the node.js event loop.

Installation

Add this line to dependencies or devDependencies in your package.json:

"node-dde": "git://github.com/thunder9/node-dde.git"

Next, run the following:

npm install

Example

Client

Example to listen to the asynchronous advise from a single service-topic-item source is the following:

var dde = require('node-dde');

client = dde.createClient('myapp', 'mytopic');

client.on('advise', function(service, topic, item, text) {
  console.log('OnAdvise: '
    + 'Service: ' + service
    + ', Topic: ' + topic
    + ', Item: ' + item
    + ', Text: ' + text);
});

client.connect();

client.startAdvise('myitem');

Example to listen to the asynchronous advise from multiple service-topic-item sources is the following:

var dde = require('node-dde');

clients = dde.createClients({
    myapp: {
        mytopic1: ['myitem1', 'myitem2'],
        mytopic2: ['myitem1', 'myitem2']
    }
});

clients.on('advise', function(service, topic, item, text) {
  console.log('OnAdvise: '
    + 'Service: ' + service
    + ', Topic: ' + topic
    + ', Item: ' + item
    + ', Text: ' + text);
});

clients.connect();

clients.startAdvise();

Example of sending an asynchronous advise to the browser in realtime using Socket.IO is the following:

var io = require('socket.io').listen(80);

var dde = require('node-dde').createClient('myapp', 'mytopic');

dde.on('advise', function(service, topic, item, text) {
  io.sockets.emit('advise', { item: item, text: text });
});

dde.connect();

dde.startAdvise('myitem');

Server

Example to push the asynchronous advise to the client is the following:

var dde = require('node-dde');

server = dde.createServer('myapp');

server.on('disconnect', function(service, topic) {
  console.log('OnDisconnect: '
    + 'Service: ' + service
    + ', Topic: ' + topic);
});

server.on('advise', function(topic, item, format) {
  console.log('OnAdvise: '
    + 'Topic: ' + topic
    + ', Item: ' + item
    + ', Format: ' + format);
});

var i = 0;
server.onAdvise = function() {
  return 'advise-' + i++;
};

setInterval(function() { server.advise('*', '*'); }, 1000);

server.register();

Methods

// Client

client = dde.createClient(service, topic, encoding)
client.connect()
client.disconnect()
client.pause()
client.resume()
client.execute(command, timeout)
client.poke(item, data, timeout)
client.request(item, format, timeout)
client.startAdvise(item, format, hot, timeout)
client.stopAdvise(item, timeout)
client.beginExecute(command, oncomplete)
client.beginPoke(item, data, format, oncomplete)
client.beginRequest(item, format, oncomplete)
client.beginStartAdvise(item, format, hot, oncomplete)
client.beginStopAdvise(item, oncomplete)
client.dispose()
client.service()
client.topic()
client.isConnected()
client.isPaused()

// Clients

clients = dde.createClients(services, encoding)
clients.connect()
clients.disconnect()
clients.pause()
clients.resume()
clients.execute(command, timeout)
clients.poke(data, timeout)
clients.request(format, timeout)
clients.startAdvise(format, hot, timeout)
clients.stopAdvise(timeout)
clients.dispose()
clients.service()
clients.topic()
clients.isConnected()
clients.isPaused()

// Server

server = dde.createServer(service)
server.register()
server.unregister()
server.advise(topic, item)
server.disconnect()
server.pause()
server.resume()
server.dispose()
server.service()
server.isRegistered()

Events

// Client

client.on('disconnected', function(service, topic, isDisposed, isServerInitiated) {})
client.on('advise', function(service, topic, item, text) {})

// Clients

clients.on('disconnected', function(service, topic, isDisposed, isServerInitiated) {})
clients.on('advise', function(service, topic, item, text) {})

// Server

server.on('before connect', function(topic) {})
server.on('after connect', function(service, topic) {})
server.on('disconnect', function(service, topic) {})
server.on('start advise', function(service, topic, item, format) {})
server.on('stop advise', function(service, topic, item) {})
server.on('execute', function(service, topic, command) {})
server.on('poke', function(service, topic, item, data, format) {})
server.on('request', function(service, topic, item, format) {})
server.on('advise', function(topic, item, format) {})

Overridable callbacks

// Client

// N/A

// Clients

// N/A

// Server

server.onBeforeConnect = function(topic) { return true; };
server.onAfterConnect = function(service, topic) {};
server.onDisconnect = function(service, topic) {};
server.onStartAdvise = function(service, topic, item, format) { return true; };
server.onStopAdvise = function(service, topic, item) {};
server.onExecute = function(service, topic, command) {};
server.onPoke = function(service, topic, item, data, format) {};
server.onRequest = function(service, topic, item, format) { return ''; };
server.onAdvise = function(topic, item, format) { return ''; };

Multi-byte string support

To specify a service / topic / item names that contain multi-byte charactors, you can pass a URL-encoded string as an argument to client methods. Decoding will be done when an encoding name is passed to createClient or createClients functions.

License

Copyright (c) 2013 thunder9 licensed under the MIT license.

About

A simplified regacy win32 DDE wrapper for node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •