将数据从 C# 发送到 javascript 的最快方法? [英] Fastest way to send data from C# to javascript?

查看:34
本文介绍了将数据从 C# 发送到 javascript 的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个独立的应用程序.其中一个是纯JS编写的UI web应用,另一个是C#编写的控制台应用.

I have two separate apps. One of them is a UI web application written with pure JS, the other one is console application written by C#.

目前我正在使用 C# 控制台应用程序计算一些变量(由于浏览器限制,无法在 JS 中完成),然后将结果写入 txt 文件.

Currently I'm calculating some variables (which can not done in JS because of browser limitations) with C# console app, then it's writing results to a txt file.

然后我用 JS 应用程序读取文件以将结果带到 UI.但该变量通常以毫秒为单位发生变化,将结果写入磁盘并再次检索它的速度非常慢.

Then I read the file with JS application to bring results to UI. But the variable often changes in milliseconds and writing results to disk and retrieving it again is pretty slow.

我能做什么?有什么建议吗?

What can I do? Any suggestions?

推荐答案

控制台应用程序实际上是一个服务器.通过本地文本文件在 Web 应用程序和服务器之间进行通信是非常规的!如果这不仅仅是你自己在一台机器上使用,那么部署给另一个用户将是非常困难的.编写一个小型服务器应用程序并以通常的方式与其通信,即将数据发布到服务器的 IP 地址并接收服务器的响应.您可以通过 websocket 通信来消除任何连接延迟(在初始连接之后).

The console application is effectively a server. Communicating between a web app and a server by means of a local text file is, well, unconventional! If this is not just for your own use on the one machine, it will be very difficult to deploy for another user. Write a small server application and communicate with it the usual way, i.e, by posting the data to the server's IP address and receiving the server's response. You can remove any connection latency (after the initial connection) by communicating over websocket.

这篇关于将数据从 C# 发送到 javascript 的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆