• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.net.UnknownHostException

 
ravindra janapreddy
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have defined my policy file 'java.policy' as follows :
grant {
// Allow everything for now
permission java.security.AllPermission;
};
I execute my server as follows :
java -Djava.security.policy=c:\assignment\java.policy -suncertify.server.DataServer
DataServer exception: Unknown host: host; nested exception is:
java.net.UnknownHostException: host
java.rmi.UnknownHostException: Unknown host: host; nested exception is:
java.net.UnknownHostException: host
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:565)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:159)
at suncertify.server.DataServer.main(DataServer.java:87)
Caused by: java.net.UnknownHostException: host
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:143)
at java.net.Socket.connect(Socket.java:425)
at java.net.Socket.connect(Socket.java:375)
at java.net.Socket.<init>(Socket.java:290)
at java.net.Socket.<init>(Socket.java:118)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:122)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
... 6 more
Is something wrong with my policy file ?
Thanks
Ravi
 
ravindra janapreddy
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have made the following changes to my policy file but I am getting the same exception
grant {
// Allow everything for now
permission java.security.AllPermission;
permission java.net.SocketPermision "*:1024-65535","connect,accept";
permission java.io.FilePermission "c:\\assignment\\scjd\\starting\\src\\suncertify\\db\\db.db","read";
};
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget about the policy file, codebase, security managers, dynamic downloading, and HTTP servers. You don't need any of this nonsense for this assignment.
Eugene.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the RMI Registry running? If you start the RMI Registry in a non default port, you need to mention that in your bind call from the RMI server.
[ June 20, 2002: Message edited by: Sai Prasad ]
 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi dear Ravinder,
I read your question. I think it is better to use security manager for the purpose of showing your skills towards assignment. UnknownHostException generally arises when client is is not able to locate server. I had also faced similar problem, But I used to get SocketPermissionException when I tried to execute my server. I would suggest you to check SocketPermission in policy file. Bind SocketPermission with "localhost" on port 1001 with accept,connect,listen. If you still have a problen then write mail to me with details at this address :
ghazab@rediffmail.com

Dont worry your problem would me surmonted.
regards,
gurpreet
 
ravindra janapreddy
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gurpreet
Thanks for the response.
I got the server bound to RMI registry after I made the following change in my code to bind the server reference to the registry
String name = "rmi://localhost:1099/DataServer";
RemoteDataInterface server = new DataServer();
Naming.rebind(name, server);
Thanks
Ravinder
 
ravindra janapreddy
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sai Prasad
I have my RMI registry started and I use the following command to start it
start rmiregistry
By default, rmiregistry is started on port 1099.
Inside my code also , I simply look up the service at port 1099 only.
Is this approach correct ?
Thanks
Ravi
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravindra,
I agree with Eugene. No need to use RMISecurity Manager, java.policy or codebase. To solve your problem, I suggest using the lines below before your rebind() call:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic