• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Applet serversocket problem

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have read most of the threads on applets and serversockets but as yet cannot come up with a solution to my problem...

I am writing an application which connects to a remote server, and to do this i used serversockets. I want now to implement an applet version. I looked into it before and couldnt, applets can only connect to the machine the applet is running on. I know about the security restrictions...but read that I might be able to get around that. Also someone wrote something about signing the connection. Im not sure but can you please help?

Thatnks in advance,

Dan
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The The Java Tutorial: Applet Security Restrictions explains what applets can and cannot do. You have two options. You can use your server to do the dirty work and report back to the applet:
The Java Tutorial: Working with a Server-Side Application or you can digitally sign the applet, assuring the user that you are who you say you are and that the applet code has not been tampered with: Advanced Programming for Java 2: Signed Applets
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

I have done smething similar ...Applets can make socket connections to servers other than the server that it came from ( though I think the server has to be running on the same machine as the web-server the applet came from).
Here are a few links ..for chatserver and clients they have applets creating sockets with the server:
http://www.csse.monash.edu.au/~lloyd/tildeProgLang/Java/Chat/
http://servlets.com/jservlet2/examples/ch10/#ex10_15

Hope this helps.
-G.
[ January 06, 2005: Message edited by: Gauri Deshmukh ]
 
Dan Lynch
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the replies. I have been working through the examples. Does anyone know about changing the .policy file to allow socket connections?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Advanced Programming for the Java 2 Platform: Security and Permissions
Be advised that you will have to install the profile file on every client. Probably not what you want to do if you are writing an applet.
I think Gauri is confused with your use of "server" to mean a physical machine as opposed to a piece of software (i.e. a web server or database server). To clarify what he was trying to say, an unsigned applet can open a socket on any port as long as the IP address is the same as the one it was downloaded from.
 
Dan Lynch
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joe,

Thanks for that. I was able to get the applet working and connecting to a serversocket. I know it shouldnt work when trying to connect to a serversocket on a different machine, but can I do this. Also I am a bit confused about the process of signing and unsigned applets. If I run my applet from a webserver on the same machine that is hosting the serversocket and then access the applet from a remote client, should it work?

Cheers,
Dan
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dan Lynch:

I know it shouldnt work when trying to connect to a serversocket on a different machine, but can I do this.



Would you by any chance be using the appletviewer provided with the JDK or be loading the HTML file directly from the file system (as opposed to loading it through a web server? That should work, as is Documented in the Applet Security FAQ


Also I am a bit confused about the process of signing and unsigned applets. If I run my applet from a webserver on the same machine that is hosting the serversocket and then access the applet from a remote client, should it work?


The applet is downloaded from the same IP address that it attempts to contact in this scenerio, so it should work signed or unsigned. The FAQ covers that as well.
 
Dan Lynch
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

What I am trying to do is run an applet, from the serversocket machine... and allow people to access the applet remotely.

The applet is downloaded from the same IP address that it attempts to contact in this scenerio, so it should work signed or unsigned. The FAQ covers that as well.



So acces the applet on the hachine from which it is hosted? From remote acces does every client have to download the .policy file?

Would you by any chance be using the appletviewer provided with the JDK or be loading the HTML file directly from the file system (as opposed to loading it through a web server?



I am loading the applet into a webpage and accessing the file system directly. I wanted to get this working before I tried it on a webserver. So the machine running the serversocket has to also host the applet? Just wondering as I will have to install the webserver on the serversocker machine and it would be much simpler not to.

Yhanks for the help thus far.

Dan
 
Could you hold this kitten for a sec? I need to adjust this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic