• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

exception in client side

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i am getting exception in HelloClient
Exception is clientjava.security.AccessControlException: access denied (java
.net.SocketPermission 127.0.0.1:1099 connect,resolve)
I don’t get the exception if I remove the following lines.
if(System.getSecurityManager()==null)
System.setSecurityManager(new RMISecurityManager());
What is the reason of it and why we set security manager .
Here is the code from wrox.
////////////////////////////////////////////
import java.rmi.*;
public interface HelloInterface extends Remote
{
public String sayHello()throws RemoteException;
}
/////////////////////////////////////////////
import java.rmi.*;
import java.rmi.server.*;
public class HelloServer extends UnicastRemoteObject implements HelloInterface
{
public HelloServer()throws RemoteException
{
super();
}
public String sayHello()throws RemoteException
{
System.out.println("going to return Hello Rmi");
return "Hello Rmi";
}
}
/////////////////////////////////////////////////
import java.rmi.*;
import java.rmi.server.*;
public class RegisterIt
{
public static void main(String args[])
{
try{
HelloServer hello=new HelloServer();
System.out.println("Object instantiated of remote");
Naming.rebind("/HelloServer",hello);
System.out.println("Object Server in the registery");
}
catch(Exception e)
{
System.out.println("Exception is in register"+e);
}
}
}
///////////////////////////////////////////
import java.rmi.*;
public class HelloClient
{
public static void main(String args[])
{
if(System.getSecurityManager()==null)
System.setSecurityManager(new RMISecurityManager());
try{
HelloInterface obj=(HelloInterface)Naming.lookup("/HelloServer");
System.out.println("object is"+obj);
String msg=obj.sayHello();
System.out.println("Message is"+msg);
}
catch(Exception e){
System.out.println("Exception is in client"+e);
}
}
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!