使用 Java 的 P2P(浏览器到浏览器) [英] P2P (browser to browser) with Java

查看:29
本文介绍了使用 Java 的 P2P(浏览器到浏览器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个在网页上运行的 Java 应用程序并允许:

I would like to implement a Java application which runs on a webpage and allows:

  • 用户 A(从其浏览器)可以向用户 B(打开浏览器)请求文件.当然,用户 A 知道用户 B 的 IP 和端口.
  • 用户 B 可以从其浏览器响应此请求.

我有哪些选择(Java 库、技术...)?

Which options (Java libraries, technologies,...) do I have?

谢谢!

推荐答案

如果你想在浏览器中使用 Java,唯一的办法就是小程序.

If you want Java in the browser, the only way to go is applets.

但是一个普通的(不受信任的)小程序:

But a normal (untrusted) applet:

  • 无法访问本地系统上的文件
  • 无法监听任何端口
  • 只能在它来自的服务器上打开套接字.

这是出于安全原因:小程序不应损害运行它的计算机的用户.

This is for security reasons: an applet should not be able to harm the user whose computer it runs on.

所以,如果你想按照你说的去做,你需要用户信任你并给你更多的权限.对于文件访问,要走的路是 JNLP API(即使用 jnlp 文件启动小程序,然后使用 javax.jnlp,特别是 FileOpenService 和 FileSaveService.然后用户需要在使用文件选择器选择文件之前确认访问.

So, if you want to do what you said, you need the user to trust you and give you more permissions. For the file access, the way to go would be the JNLP API (i.e. start your applet with a jnlp file, and then use the API in javax.jnlp, specially FileOpenService and FileSaveService. The user then needs to confirm the access before choosing a file with a file chooser.

这对网络访问仍然没有帮助 - 如果您不想代理服务器上的所有内容(这不是点对点的),您的小程序需要在那里有合适的 SocketPermissions.为此,您需要签署您的小程序,并请求用户的所有权限(我认为没有更细粒度的方法只提供必要的 SocketPermissions).您可以在 jnlp 文件中执行此操作.

This still does not help for the network access - your applets need to have suitable SocketPermissions there, if you don't want to proxy everything on your server (which would not be peer-to-peer). For this, you need to sign your applet, and request all permissions from the user (there is no finer-grained way to give only the necessary SocketPermissions, I think). You can do this in the jnlp-file.

这篇关于使用 Java 的 P2P(浏览器到浏览器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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