File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI Server problem

 
Arvind Chavar
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have create d simple DateServer program.When I am trying to run my server it is not able to create a socket and bind.Can anyone please help.It has taken lot of time and has been annoying.
Following is the error out put
C:\COURSE_WORK\EE633\TextCode\ch23\Server>java -Djava.security.policy=policy.all
DateServer
Exception in thread "main" java.rmi.ConnectException: Connection refused to host
: 169.254.101.152; nested exception is:
java.net.ConnectException: Connection refused: connect
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S
ource)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
ource)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at DateServer.main(DateServer.java:30)

My policy.all contains
grant {
permission java.security.AllPermission "", "";
};
*************** DateServer.java ****************************
import java.util.Date;
import java.rmi.RemoteException;
import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject;
public class DateServer extends UnicastRemoteObject implements DateServerI{
/** Creates new DateServer */
public DateServer() throws RemoteException{
}

public String getDate()throws RemoteException{
return ("From Date Server : " + new Date());
}

public static void main(String args[]) throws Exception{
DateServer execute = new DateServer();
Naming.rebind("Date Server",execute);
}
}
***************** DateClient.java ***********************
import java.rmi.Naming;
public class DateClient{
/** Creates new DateClient */
public DateClient() {
}

public static void main(String args[]) throws Exception{
String url = "rmi://" + args[0] + "/Date Server";
DateServerI client = (DateServerI)Naming.lookup(url);
String result = client.getDate();
System.out.println(" Result : " + result);
}
}
/****************** DateServerI.java - Interface ***************
import java.rmi.Remote;
import java.util.Date;
import java.rmi.RemoteException;
public interface DateServerI extends Remote{
public String getDate()throws RemoteException;
}
Thanks,
Arvind
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you start rmiregistry first?
Looks like it can not connect to the registry.
Yarik
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Yaroslav is probably right. Here's a little more explanation if you want it.
Near the bottom of your exception trace, you'll notice the trouble starts with the call to Naming.rebind(). Your server code is attempting to publish the stub as a remote service.
What you are binding to is a network service known as rmiregistry. It runs on port 1099 by default, unless of course it's not running at all. So you're being refused at 1099 because no one is listening to the (re)bind request.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Arvind Chavar
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Thanks!!.I resolved the problem.Thanks again for your help.
Arvind
 
Eleni G. T
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Guys,

I have a problem with Rmi. I have a simple Client and a Server with a method that client says hello to the Server.
The program works to some machines, and some others it doesen't work and i get the following excetion :

java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested excepti
on is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:567)
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.invoke(UnicastRef.java:101)
at RmiServer_Stub.getRound(RmiServer_Stub.java:46)
at RmiClient.main(RmiClient.java:53)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
... 5 more

For some reason i dont rely understant it tries to connect to localhost!!! but when the server is down (not running in the remote host) it says it cannot connect to the server IP....isnt that strange?!!
Please give me any ideas!!

Thanks

Eleni
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic