Home arrow static arrow Java Programming [Archive] - RMI question
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - RMI question
This topic has 3 replies on 1 page.

Posts:346
Registered: 1/15/04
RMI question  
Jul 16, 2004 3:00 AM



 
I want my client to be able to call the getInfo() method and get an Info object.

I try to create a TempServerImpl object in my main, but it keeps throwing an exception,
I have launched "start rmiRegistry"

Any ideas what I'm missing in this basic RMI program.

[code]
public class TempServerImpl {

public TempServerImpl() throws Exception{
super();
}

public Info getInfo(){
return new Info("some temperature data returned");
}

public static void main(String args []) throws Exception{
TempServerImpl tempServer = new TempServerImpl();
Naming.rebind("//localhost/TempServer", tempServer);
}
}

//************

public interface TempServer extends Remote{
public Info getInfo();
}

//*************

public class Info implements Serializable{
private String data;

public Info(String data) {
this.data = data;
}
public String toString(){
return this.data;
}
}
//****************
 

Posts:319
Registered: 11/8/00
Re: RMI question  
Jul 16, 2004 3:16 AM (reply 1 of 3)



 
From your code example it doen't appear that you have implemented the interface
TempServer


Also what exception do you get?
 

Posts:346
Registered: 1/15/04
Re: RMI question  
Jul 16, 2004 3:33 AM (reply 2 of 3)



 
must have screwed up the cut n paste, yes, it implements the TempServer Interface
Exception I get is
java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused: connect

[code]
public class TempServerImpl implements TempServer{
public TempServerImpl() throws Exception{
super();
}

public Info getInfo(){
return new Info("some temperature data returned");
}

public static void main(String args []) throws Exception{
TempServerImpl tempServer = new TempServerImpl();
Naming.rebind("//localhost/TempServer", tempServer);
}
}

//************

public interface TempServer extends Remote{
public Info getInfo();
}

//*************

public class Info implements Serializable{
private String data;

public Info(String data) {
this.data = data;
}
public String toString(){
return this.data;
}
}
//*********
[\code]
 

Posts:319
Registered: 11/8/00
Re: RMI question  
Jul 16, 2004 4:23 AM (reply 3 of 3)



 
i tried compilling your example and got a number of errors,

1. the method getInfo needs to throw a remote exception. - I got the error when running rmic.
2. the TempServerImpl class needs to be seriliazable. - I set it to extend UnicastRemoteObject.

I still can't get it working but i think the remaining problems are issues with my classpath and i don't want to **** it up again.

here is a copy of the code i have.

import java.rmi.Naming;import java.rmi.RemoteException;import java.rmi.server.UnicastRemoteObject; public class TempServerImpl extends UnicastRemoteObject implements TempServer{	public TempServerImpl() throws Exception	{		super();	} 	public Info getInfo() throws RemoteException	{		return new Info("some temperature data returned");	} 	public static void main(String args []) throws Exception	{		TempServerImpl tempServer = new TempServerImpl();		Naming.rebind("//localhost/TempServer", tempServer);	}}

import java.rmi.Remote;import java.rmi.RemoteException; public interface TempServer extends Remote{	public Info getInfo() throws RemoteException;}

import java.io.Serializable; public class Info implements Serializable{	private String data; 	public Info(String data)	{		this.data = data;	} 	public String toString()	{		return this.data;	}}
 
This topic has 3 replies on 1 page.