• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

URL Connection

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using Applet client and servlet in the server side. The applet uses URL Connection for communicating with the servlet. My machine is not registered with a naming host(DNS). I am setting the url parameter as "localhost" for creating the URL class object.Then it is working perfect in my machine.
That is
URL url=new URL("http://localhost:8080/km/servlet/ChatServlet";);
URLConnection con=url.openConnection();
But I want to test it from another machine, keeping my machine as the server (I am using Tomcat server).It is a multicast application. So I changed the url to my machine's domain name. I tried both domain and IP address for the url. When I set the url parameter like this, It is throwing some security exception, when the applet client tries to open the URL Connection to the servlet.
That is
URL url=new URL("http://elizabeth:8080/km/servlet/ChatServlet";);
or
URL url=new URL("http://192.168.1.22:8080/km/servlet/ChatServlet";);
Even when I tested the above url with the applet client running in my machine , it is throwing the same exception.
The applet client is opening the connection when it is run in my machine (where the server is running)setting the url to "localhost". But when I test it with "localhost", I cannot run the applet client in another machine.
Is this because, my machine is not registered with DNS, so that when the URL is resolved, it is not finding such a server and throw the exception?
Or is it because of any other problem?
Please give me a solution..
It is very urgent..
Thanks
Elizabeth.
 
Saloon Keeper
Posts: 21981
150
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandbox rules say that an unsigned Java applet can only open a network connection to the same server that the applet was loaded from. It's not a naming problem at all.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URL connection = new URL(this.getCodeBase(),"/servlet/classfile name");
URLConnection servletConnection = connection.openConnection();
try this
i hope it will help u
venkat
 
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic