P2P (browser to browser) with Java

天涯浪子 提交于 2019-12-10 04:25:01

问题


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

  • User A (from its browser) can request a file to User B (with its browser opened). Of course User A knows User B's IP and port.
  • User B can respond this request from its browser.

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

THANKS!


回答1:


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

But a normal (untrusted) applet:

  • can not access files on the local system
  • can not listen at any ports
  • can only open sockets on the server it came from.

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

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.

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.



来源:https://stackoverflow.com/questions/5211407/p2p-browser-to-browser-with-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!