Hi all,
I've been trying to get an RMI program working and I have reached my limit of knowledge on how to fix it. I will attach my code. My first question is, is my server even running. At the moment i use Netbeans to run my program and i'm assuming that netbeans looks after all the nitty gritty in the background but to be honest i don't believe this is correct. I try to follow examples as best i can but I run into errors one after the other.
My first problem is the sever code.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package server;
/**
*
* @author Mike
*/
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class MessageServer {
public static void main(String args[]) {
try {
Message obj = new MessageImpl();
System.out.println("here3");
Naming.rebind( "Message_Server",obj);
System.out.println("Server in Registry");
}catch (Exception e) {
System.out.println ("Message_Server error: " +
e.getMessage());
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package server;
/**
*
* @author Mike
*/
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class MessageImpl extends UnicastRemoteObject implements Message {
private String message;
public MessageImpl() throws RemoteException{
super();
}
public String getMessage() throws RemoteException {
return message;
}
public void setMessage(String message) throws RemoteException {
this.message = message;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package server;
/**
*
* @author Mike
*/
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Message extends Remote{
public String getMessage() throws RemoteException;
public void setMessage(String message) throws RemoteException;
}
I start the rmiregistry and run this through the command console and bizarrely after several attempts to get it running it eventually will. For example, at the moment the code tells me that the sever is running. If however i restart my computer and go through the exact same process again it will not run first time.
Can anyone tell me if what i am doing is correct? Also does any one know how to run this in a netbeans project or do i just have to run it manually in the command console.
Any help is greatly appreciated!
Michael