I'm currently examining the possibilities of edge.js because it would greatly help us with our current project. What I need is this: I do have a C# DLL (compiled for 4.5.1) that we use in our standard C# applications. This DLL contains a TcpMessageListener
class that I would usually instantiate and use like that (in a Windows Forms, for example):
using MyAssembly.Tools;
namespace MyApplication
{
public partial class Form1 : Form
{
TcpMessageListener myListener;
public Form1()
{
myListener = new TcpMessageListener();
myListener.Port = 22222;
myListener.MessageReceived += new EventHandler<MessageEventArgs>(MessageReceived);
myListener.Start();
}
public void MessageReceived(Object sender, MessageEventArgs e)
{
[...] // My message handling code here
}
}
}
The code above usually creates a listener when the application starts up and starts listening on the given port (which I can quickly check with netstat or similar).
Now I want to make the same thing happen when I run my node code, but I somehow miss the point and do not get on track. I should add that I am completely new to node.js and just diving into it, please be patient with me.
From what I've seen in all the samples on the edge.js site, I tried it like this:
var http = require('http');
var port = process.env.port || 1337;
var listen = require('edge').func({
assemblyFile: 'dll\\MyAssembly.dll',
typeName: 'MyAssembly.Tools.TcpMessageListener',
methodName: 'Start'
});
listen(null, true);
http.createServer(function (req, res) {
console.log(req.url);
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port);
But there are two issues: first of all the code above obviously does not seem to create an instance of the listener, but I could not figure out how I would create an instance of the TcpMessageListener
class and then call its Start()
method.
From the given code, how would you create a listener and make it listen on a given port in the background with node.js and edge.js? I feel like I just need a stable starting point before going deeper.
(The final goal would be a background listener that receives certain messages. When a message is received, the web user should be presented the last received message content instead of the "Hello World". I think I could figure out everything else from there on.)
Try this: I was having similar issues (and still having some), but you may need to store your .NET objects in a static object because edge will lose context after a call: http://mcluck90.tumblr.com/post/89814519378/getting-started-with-edge-js