質問

Is it possible to write a Java applet that can be a server on the client machine within the client's local network?

To be more specific, what I am looking to do is tunnel non-web traffic over the web. The sender would send to the applet, which would then forward the received data back to the server.

Is this sort of thing possible? What are the restrictions that might get in the way?

Note: I know that the applet can connect back to the server, that isn't an issue. The issue is whether or not an applet can listen for a connection / data on a local, client-side port.

役に立ちましたか?

解決

An unsigned applet can only connect the host they come from.

A signed applet can do any connection you want and can listen on tcp-ip ports.

Source : http://docs.oracle.com/javase/tutorial/deployment/applet/security.html

他のヒント

Server does not connect to anywhere. Server opens server socket and is listening.

In past as far as I remember the server socket was restricted in MSIE and was permitted in Netscape (do you remember such browser?) :)

I personally have not been writing applets for the last 10 years, so I have no idea what happens now with currently existing browsers, but it is very easy to check. Just write the shortest applet you can and put code new ServerSocket(1234).accept(); into its init() or start() method. If no exception was thrown you can write applet that functions as a server. Otherwise you cannot.

Just try it with all available browsers. 20 minutes work and you are done. Good luck. I'd will be glad to know about the results.

Generally, it cannot.

One reason why is that applets tend to be ran within security constrained environments, which means that they are denied the ability to open server sockets.

There are ways around such a restriction, basically you can specify a special security policy for the applet, or run it in a special unconstrained container; but why bother when you can just port the contents of your application into a standard servlet, or even a stand-alone server?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top