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.
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 =)