learn java
The moose likes Distributed Java and the fly likes RMI Server problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI Server problem" Watch "RMI Server problem" New topic

RMI Server problem

Arvind Chavar
Ranch Hand

Joined: May 16, 2001
Posts: 53
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
Exception in thread "main" java.rmi.ConnectException: Connection refused to host
:; 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
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
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;
Yaroslav Chinskiy
Ranch Hand

Joined: Jan 09, 2001
Posts: 147
Do you start rmiregistry first?
Looks like it can not connect to the registry.
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

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

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Arvind Chavar
Ranch Hand

Joined: May 16, 2001
Posts: 53
Hi Guys,
Thanks!!.I resolved the problem.Thanks again for your help.
Eleni G. T

Joined: Nov 03, 2004
Posts: 1
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:; 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
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
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!!


I agree. Here's the link: http://aspose.com/file-tools
subject: RMI Server problem