user411103
user411103

Reputation:

P2P (browser to browser) with Java

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

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

THANKS!

Upvotes: 6

Views: 1001

Answers (1)

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74810

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.

Upvotes: 6

Related Questions