Using .NET DLL in Node.js / serverside javascript

I have a project for pets, which is an online game, the entire game engine is written in C #, and I would like to know if I can call the functions of this existing assembly (.dll) from a solution created using Node.JS, Socket.IO, Express, etc.?

The game engine itself is quite complete; tested and reliable I hope that there is some neat way to reveal its functionality without extra costs.

UPDATE :

To answer my own question a bit ... I ended up creating my own web socket server (based on the most recent 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 some changes) I can use my existing game engine.

UPDATE 2 A project that does exactly what I was looking for now exists - http://tjanczuk.imtqy.com/edge/#/

UPDATE 3 Edge.js, which supports the latest versions of nodes, and the .net kernel with the new edge-js package.

Support Node.Js 6.x, 7.x, 8.x, 9.x, 10.x, 11.x Support .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

+58
c # serverside-javascript
Jan 11 2018-11-11T00:
source share
8 answers

If all you want to do is deploy a lightweight HTTP server while still programming in C # and .Net, you should give Kayak a chance. It is a lightweight HTTP server for C # and behaves like node.js in that sense.

kayakhttp

Update:

If you are looking for a lightweight HTTP server for handling web requests, you have a couple of alternatives today:

  • ServiceStack (recommended)
  • Microsoft webapi
  • Nancyfx

As far as I know, all of the above works on some version of Mono, so you can still place them on both Windows-based systems and Unix.

+17
Jan 26 '11 at 18:46
source share

Check out the edge.js project that I started ( http://tjanczuk.github.com/edge ). It provides a mechanism for running .NET and node.js code in the process. Edge.js allows you to call .NET code from node.js and node.js code from .NET. It organizes data between .NET and node.js, and also harmonizes thread models between multi-threaded CLRs and single-threaded V8s.

Using edge.js, you can access the islands of the previously existing .NET code from node.js, which seems to fit your scenario.

+27
Mar 26 '13 at 6:16
source share

I recently ran into the same call (requiring calling C # code from node.js javascript). I had 1000 lines of complex C # code that I really didn't like porting to javascript.

I decided as follows.

  • The corresponding C # code is basically 1-2 classes in a DLL assembly
  • A COM interface is defined, which is a subset of the C # class interface and implemented this interface in the C # class. Thus, the DLL became a COM server in the process.
  • Implemented a node.js DLL extension that runs my C # COM class using the standard Win32 COM API and routes method calls from node.js javascript to C # code using the COM interface.

This solves the problem if you only want to make calls in one direction. I also had a requirement to make calls from C # to javascript. This is much more complicated. Need to:

  • Embed a COM object in the node.js DLL extension (ATL helps here)
  • Pass the interface link of this COM object to C # code (COM Interop)
  • Routing calls through a COM object for V8 objects in node.js

Perhaps if I have extra time, I could make an example project from this.

+25
Jan 15 '12 at 19:12
source share

.Net can be written. In short, you write a regular native addon and add .Net calls through CLI / C ++. Net dll calls.

In practice, you usually create a C # library of libraries that you then call from the CLI / C ++ node addon project. There are few delicacies, such as ensuring that the actual node add on definition file is compiled without CLR support, so node can load it correctly.

You can check: https://github.com/saary/node.net for an example of how this can be achieved.

+8
Nov 22 '11 at 10:55
source share

The following answer is deprecated but still useful for understanding Node.js from the first release
Node.js is now also available for Windows at nodejs.org. No cygwin requirement anyway.

First of all, at the moment there is no native Windows Node.js port, there is only a version of cygwin (but I suspect that you already knew this).

There was a node module floating somewhere in GitHubs that provided a wrapper for invoking native libraries, but an iirc that only worked with .so libs.

Therefore, if you want to use the C # DLL, you will first need to write your own Node.js extension as an interface:
https://www.cloudkick.com/blog/2010/aug/23/writing-nodejs-native-extensions/

From this extension, you have to load the DLL and transfer the calls from Node.js to C # code, this means that you need to write low-level C / C ++ code and convert C # values ​​to V8 material.

I only have experience with C ++ and V8, it is a little difficult to start, as the code examples are a bit sparse, as well as C ++ classes that are not trivial. But I wrote a small JS game engine of a kind that uses the C ++ OpenGL backend, it is incomplete (and there are almost no comments), but this may give you some ideas.

Note. There are several projects in the wild that provide somewhat automatic wrapping for V8, but this is only C ++.

So in conclusion, I think it will be quite adventurous to get C # wrappers to work, but it should be possible.

+7
Jan 11 2018-11-11T00:
source share

You may succeed with this project , which is the Node.js port for .NET. I have not used it myself, but with your own .NET implementation, you should theoretically be able to do what you need.

You can also go in the other direction and try to carry out the transfer (aka: recompile if you are not deeply connected to Windows), your C # game engine to Mono and see if you can then defer the wrapper from this.

+2
Jan 25 2018-11-18T00:
source share

I know this is an old question, but wanted to answer in the current answer. With support for IIS 7.5 and .Net 4.x, Websockets are supported, although using the SignalR library is likely to be the least resistance. It looks like a socket.io library for NodeJS.

As for accessing .Net code through NodeJS, your best options are Edge.js, which create a mixed assembly with C / C ++, exposing your .Net code either using a command line application (it is best to use input channels / output) or through a service (TCP or another).

I find Edge.js very limited and do not offer much over the console console interface .. and I believe that the service may be best for a more complex interface. At this point, you can best do the rest of the project in .Net if you do not have an investment in NodeJS that replaces these difficulties.

+1
Apr 18 '13 at 8:48
source share

Edge.js supports the latest nodes and the .net core with the new edge-js package.

Support Node.Js 6.x, 7.x, 8.x, 9.x, 10.x, 11.x .NET Support

Core 1.0.1 - 2.x on Windows / Linux / macOS. Mono Runtime Support

4.8.x - 5.x.

Can be installed ( npm edge-js ) with https://www.npmjs.com/package/edge-js

0
May 20 '19 at 14:44
source share



All Articles