Advertisement

[java] Applet <-> Socket

Started by March 23, 2000 02:02 PM
5 comments, last by lkingx 24 years, 7 months ago
Hello, can i connect me to a socket from an applet, when the socketserver isn''t on the same pc as the applet?
If what ive understood what ive been reading then the answer is no. It violates the security thingy that Sun has got put on applets.

That description sucks, so I hope one of the smart people answers this post too.

PEACE
GAZZ
Advertisement
Sorry for my bad english, because Im from germany.
It''s supposed to be valid for you to connect to the server that the applet is downloaded from, nowhere else. However I''ve heard that in practice that sometimes does not happen.

JoeG
joeG
With Java versions 1.1 and earlier you can communicate with the server that served the applet, but not any other server (and I think you are even prevented from communicating with other sockets on the machine executing the applet? Does anyone know if the sandbox allows this?).

It is also possible to connect to socket servers on machines other than the one serving the applet if you modify the security policies on the computer executing the applet (at least with JDK 1.2 and greater).

Modifying security policies is not something you can expect the average user to be able to do. It also requires JDK 1.2+ support, meaning that the user has to have the Java 2 Plugin installed (since almost every browser only supports the 1.1 and earlier versions of the Java platform).

So if this applet is designed to be distributed to the Internet you will have to only communicate with the server that served the applet in the first place.
You can always connect to URLs to get files, but you cannot send anything besides a GET, or maybe a POST. So opening a socket to a server that isn''t the one that the applet is from is kind of a far out thing to do, unless you are writing and irc, ftp, or some similar client. I believe that with an electronically signed applet it is possible to connect to foreign sockets without modifying the security manager of the client''s computer, vis gamedev''s java irc client.

Other than that, one workaround would be to have the client download the applet from the server to which it needs to connect. The applet doesn''t have to reside on the web server that serves up the webpage that has the applet.
Advertisement
You can do it in a round about type of way. It''s really annoying but the answer is yes if you use tunneling. In otherwords your applet connects to a socket on the server the applet was served from and then the server opens a socket to wherever and passes the data back and forth from the applet. Like I said it is kind of annoying to write the extra code but if it has to be done it can be =)

Tim Holwig
fabel@mindspring.com

This topic is closed to new replies.

Advertisement