GWT 中需要 RPC 吗?
我是 GWT 新手。我正在使用 eclipse 创建一个简单的应用程序。在了解了如何在开发模式和生产模式下运行项目等基础知识之后,但有一件事我无法理解。在 google 中,他们给出了一个示例构建项目,当我完成该项目时,我又看到了一个名为 RPC in GWT 的教程。在这里,他们更改了以前的代码并实现了新的代码。 在 GWT 中,所有内容都转换为 javascript,但是当我们使用 RPC 时,RPC(服务器)代码将在服务器上采用 java 字节格式。我的问题是为什么我们必须实现RPC?什么情况下需要使用RPC?
I'm new to GWT. I'm using the eclipse to create a simple application. After understood the basics like, how to run the project in development mode and production mode but one thing i'm unable to understand. In google they given a sample build project, when i finished with that i seen one more tutorial called RPC in GWT. Here they changed the previous code and implemented the new one.
In GWT everything is converted into the javascript but when we are using the RPC, then RPC(server) code will be in the java bytes format at server. My question is why we have to implement the RPC? What's the need to use RPC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用RPC的需要是让你的Client通过异步调用的方式与服务器通信。 RPC 以某种方式抽象此调用,以便调用服务器上的方法类似于调用普通对象的方法。因此,调用本地方法和调用“远程”方法基本上是相同的。
(当然,您也可以编写从不调用服务器的客户端代码。)
The need to use RPC is to let your Client communicate with the server via asynchronous calls. RPC abstracts this call in a way so that calling a method on a server is analog to calling a method on a normal object. So, calling a local method and calling a "remote" method becomes basically the same.
(Of course, you could also write client code which never calls a server.)
想象一下,您想要调用在服务器端实现的操作,例如登录用户。
服务器上有一个注册用户的数据库。 clinet(浏览器中的javascript代码)必须将用户的名称和密码发送到服务器。然后,服务器(java 代码)联系数据库并验证用户身份,并将 true 或 false 返回给客户端。这样,您就可以从客户端远程调用服务器上的操作(登录过程),并得到响应。因此得名 RPC。
这里的关键是理解客户端和服务器端。在客户端,您有 javascript,但使用 java 脚本您无法访问数据库。此外,您没有每个客户端(浏览器)上所有注册用户的数据库。所以你有包含数据库的服务器端以及连接到该数据库的java代码。每个客户端只是通过RPC告诉服务器进行相应的操作并返回结果。
Well imagine that you want to call an operation that is implemented on the server side, for example login a user.
There is a database of registered users on the sever. The clinet (javascript code in browser) must send the name and password of the user to server. The server (java code) then contacts the database and authenticates the user and returns a true or false back to client. This way you have romotely called an operation (the login procedure) on the server from client, and got a response back. Hence the name RPC.
The key here is to understand client side and server side. On the client side you have javascript, but with java script you cannt access a database. Additionally you don't have the databse of all registered users on every client (browser). So you have the server side that contains the databse and also the java code to connect to this database. Each client just tell the server to do the corresponding operation via RPC and gets the result back.