web前端调用dll_从前端加载的DLL调用函数javascript(加载DLL在客户端JavaScript)

我已经完成了。解决方案是使用EdgeJS作为NodeJS V8和C#CLR之间的桥梁。边加载DLL并在V8和CLR之间创建通信通道,这些消息是Func>或function(payload, callback)的函数,这些函数在每个语言VM之间编组。

我会后下面的代码示例:

C#

public abstract class NetWebSocket

{

private Func> SendImpl { get; set; }

protected NetWebSocket(Func> sendImpl)

{

this.SendImpl = sendImpl;

}

protected abstract Task ReceiveAsync(string message);

public Func> ReceiveImpl

{

get

{

return async (input) =>

{

Console.Out.WriteLine(input);

await this.ReceiveAsync((string) input);

return Task.FromResult(null);

};

}

}

protected async Task SendAsync(string message)

{

await this.SendImpl(message);

return;

}

}

public class MyNetWebSocketImpl : NetWebSocket

{

public CHello module;

private string JSONCodelineDataRepr = "not set";

public MyNetWebSocketImpl(Func> sendImpl) : base(sendImpl)

{

// do other stuff after calling the super class constructor

module = new CHello();

module.DocumentReadEvent += this.DocumentReadEventHandler;

module.DocumentReadErrorEvent += this.DocumentReadErrorEventHandler;

// uncomment after the websocket communication works

module.Start();

}

protected override async Task ReceiveAsync(string message)

{

// not really needed because only the NodeJS Server listens to C# .NET Server messages

Console.WriteLine(message);

if (message.Equals("shutdown"))

{

module.Close();

}

// not necessary (can comment the send function call)

// if I eventually receive a message, respond with the JSON representation of the Patient ID Card

await this.SendAsync("I received a message from you, but I'll ignore it and send you the Patient" +

" ID Card Data instead.. I'm a fish, so start phishing! PersonData = " +

JSONCodelineDataRepr);

return;

}

private async void DocumentReadEventHandler(string args)

{

this.JSONCodelineDataRepr = args;

await this.SendAsync(args);

}

private async void DocumentReadErrorEventHandler(string args)

{

await this.SendAsync(args);

}

}

public class Startup

{

public static MyNetWebSocketImpl ws;

public async Task Invoke(Func> sendImpl)

{

ws = new MyNetWebSocketImpl(sendImpl);

return ws.ReceiveImpl;

}

}

的JavaScript/的NodeJS

(function(e,d,g,e){

var edge = require('edge'),

http = require('http'),

WebSocketServer = require('ws').Server,

swipe = edge.func('./dlls/ActiveXCOM.dll');

var server = http.createServer(function(req,res){

res.writeHead(200, {'Content-Type' : 'text/html'});

res.end((

function() { /*

var ws = new WebSocket('ws://' + window.document.location.host);

ws.onmessage = function (event) {

console.log(event.data);

var div = document.getElementById('jsonOutput');

div.innerHTML = event.data;

}

ws.onopen = function (event) {

// send something to the server

ws.send('I am the client from the browser calling you, the NodeJS WebSocketServer!');

}

ws.onclose = function (event) {

alert('websocket closing');

}

window.onbeforeunload = function myonbeforeUnload() {

return "Are you sure?";

}

window.onunload = function myonunload() {

confirm('Are you really sure?');

ws.close();

return "Are you really sure?";

}

*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]);

});

var wss = new WebSocketServer({server: server});

wss.on('connection', function(ws) {

var sendImpl = function (message, callback) {

console.log(message);

ws.send(message);

callback();

};

var receiveHandler = swipe(sendImpl, true);

ws.on('message', function (message) {

receiveHandler(message);

});

ws.on('close', function close(){

console.log('****************************The client disconnected!');

receiveHandler('shutdown');

delete receiveHandler;

});

});

server.listen(process.env.PORT || 8080);

module.exports = this;

})();

我希望实现是显而易见的。如果您对此有任何疑问,请不要犹豫给我写信。

编码快乐!

[别听那些反对者!]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:1024 设计师:我叫白小胖 返回首页
评论

打赏作者

Nerd Muscle

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值