简体   繁体   English

服务器上的C ++代码,在客户端计算机上运行

[英]C++ code on server, running on client machine

Is it possible to write C++ code to interface with a server, but to be executed on client side, but on the browser instead of native? 是否可以编写C ++代码与服务器接口,但要在客户端执行,而要在浏览器上执行,而不是在本机上执行?

Like, for example, imagine using open source classes so that you produce a file. 例如,想像一下使用开源类,以便生成文件。 But because you don't want all this work to be done on the server, you run it on the browser. 但是,由于您不希望所有这些工作都在服务器上完成,因此可以在浏览器上运行它。

So that the client gives a file or two or more as inputs, then the code runs on his machine, the final result is produced, then this file is uploaded to database on the server. 这样,客户端就可以提供一个或两个或多个文件作为输入,然后代码在其计算机上运行,​​产生最终结果,然后将该文件上载到服务器上的数据库。

please see google native client project. 请参阅google native client project。 http://code.google.com/p/nativeclient/ http://code.google.com/p/nativeclient/

This is strange question. 这是一个奇怪的问题。

You can prepare binaries that do task that you want done on client side and make server send proper binary to client when asked for it. 您可以准备在客户端执行您要完成的任务的二进制文件,并使服务器在要求时将适当的二进制文件发送给客户端。 Client then runs this binary and returns results to server. 客户端然后运行此二进制文件并将结果返回到服务器。

It is possible if you know configurations of client machines (binaries must work on them). 如果您知道客户端计算机的配置(二进制文件必须在它们上面工作),则有可能。 Also it have to be some security layer implemented - you don't want to allow every binary run on client (imagine man-in-the-middle attack when some malicious code is run on client). 此外,还必须实现一些安全层-您不想让每个二进制文件都在客户端上运行(想象一下,当在客户端上运行某些恶意代码时,中间人攻击)。

I think your request contradicts with the idea behind server-side programming. 我认为您的要求与服务器端编程背后的思想背道而驰。 The main purpose in using server-side programs is to make use of infrastructural components like database, network, etc. in a controlled manner. 使用服务器端程序的主要目的是以受控方式使用基础结构组件,例如数据库,网络等。 (The most typical usage of server-side applications are web sites with server side coding like JSP and ASP.) (服务器端应用程序的最典型用法是带有服务器端编码的网站,例如JSP和ASP。)

Since servers are machines that are to be kept secure, a remote application should not be permitted to make changes or access filesystem freely. 由于服务器是要保证安全的机器,因此不应允许远程应用程序进行更改或自由访问文件系统。 If you want to do changes on a server like doing database operations or reading/writing files, you should use applications that run on the server or provide interfaces like web services or web sites to remote client applications. 如果要在服务器上进行更改(例如执行数据库操作或读取/写入文件),则应使用在服务器上运行的应用程序或向远程客户端应用程序提供Web服务或网站之类的界面。

So there are a couple solutions when if you want to do work on the browser, then have the results posted in a server database. 因此,如果您想在浏览器上进行工作,然后将结果发布到服务器数据库中,则有两种解决方案。

First of all, you must set up your server ready for database work. 首先,您必须设置服务器以准备进行数据库工作。 I have done this using the MEAN stack, set up a MongoDB and interfaced it with the Mongoose API. 我已经使用MEAN堆栈完成此操作,设置了MongoDB并将其与Mongoose API接口。

Now, for the meat of the question, there are many examples of browsers doing intensive work. 现在,对于问题的实质,有许多浏览器进行大量工作的示例。 The majority of these applications thought is not C++, but it is Javascript. 这些应用程序中的大多数不是C ++,而是Javascript。

If you really want to focus on C++ (like i did in the past, in the time i asked this question, wanting to make something big for college), then you could do one of the following: 如果您真的想专注于C ++(就像我过去一样,当时我问这个问题,想为大学做点大事),那么您可以执行以下一项操作:

*Use Google Native Client (NaCl). *使用Google Native Client(NaCl)。 This is a sandbox for running compiled C and C++ code in the browser efficiently and securely, independent of the user's operating system. 这是一个沙箱,用于独立于用户的操作系统,在浏览器中高效安全地运行已编译的C和C ++代码。 *Maybe you should want to check out Emscripten, which is a framwork for translating C and C++ code to jaascript. *也许您应该要查看Emscripten,这是将C和C ++代码转换为jaascript的框架。 This way, you can have your C or C++ binaries that worked, and have them translated to Javascript, in order to have them work in the browser too. 这样,您就可以使C或C ++二进制文件起作用,并将它们转换为Javascript,以便它们也可以在浏览器中起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM