I have a pet project that is an online game, the entire game engine is written in C# and I would like to know if there is anyway I can call the functions of this existing assembly (.dll) from a solution built using Node.JS, Socket.IO, Express etc?
The game engine itself is pretty complete; tested and robust. I am hoping there is some neat way of exposing its functionality without too much overhead.
UPDATE:
To answer my own question a little.. I have ended building my own web socket server (based on the most current web socket protocol document). It is written in C# and compiled using Mono so that it can be hosted on a Linux box running mono and therefore (with a few tweaks) I can use my existing game engine.
UPDATE 2 A project that does exactly what I was originally looking for now exists - http://tjanczuk.github.io/edge/#/
UPDATE 3 Edge.js supporting node's last versions and .net core with a new edge-js package.
Support for Node.Js 6.x, 7.x, 8.x, 9.x, 10.x, 11.x Support for .NET Core 1.0.1 - 2.x on Windows/Linux/macOS. Support for Mono runtime 4.8.x - 5.x.
Can be installed from https://www.npmjs.com/package/edge-js
Once you have a DLL, utilizing the interface through Node. js is pretty easy (read on!). Converting a legacy C or C++ application into a DLL can be a good integration choice when automation is too cumbersome.
While JavaScript is client-side, Node, being executed server-side, presents some vulnerabilities to different threats. Moreover, even though the core of Node. js is secure, the use of third-party components may result in additional risks.
C# app starts your node app and you do IPC by writing to the node process inputstream and read it's outputstream. Your node process runs a socket server and your C# app does requests over tcp. You use a 3rd process/server like Redis or a Message Queue. Anything that allows you to share data like files..
Node. js is a runtime environment to allow JavaScript to not only be run in the browser, but also on the server (or almost any environment, really). That also expanded the types of applications that could be built with the language since it wasn't tied to only the client-side anymore.
Check out the edge.js project I started (http://tjanczuk.github.com/edge). It provides a mechanism for running .NET and node.js code in-process. Edge.js allows you to call .NET code from node.js and node.js code from .NET. It marshals data between .NET and node.js as well as reconciles the threading models between multi-threaded CLR and single threaded V8.
Using edge.js you can access islands of pre-existing .NET code from node.js, which seems to match your scenario.
I've been recently faced with the same challenge (requirement to call C# code from node.js javascript). I had 1000s of lines of complex C# code that I really didn't like to port to javascript.
I solved if as follows.
This solves the problem if one only wants to make calls in one direction. I also had the requirement to make calls from C# to javascript. This is a lot harder. One has to:
Maybe if I have some extra time, I might make an example project out of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With