开发者

P2P (browser to browser) with Java

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 (Ja开发者_高级运维va libraries, technologies,...) do I have?

THANKS!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜