1

I am pretty new in Java RMI and i am having a problem of Not Bound Exception. I know there are a lot of posts here but anything i have tried the last hours did not help really..

Here is the code of the server and the client. Any help is good, thanks in advance.

One last thing, the exception is found when i am running Master, when i am running server no errors are found.

Master:

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.util.Scanner;
import java.rmi.registry.LocateRegistry;

public class Master {

    private ITaskBag1 tb;
    private String name = "rmi://" + "127.0.0.1" +":"+1099+"/TaskBagServer";
    private int rescount = 0,listcount=0;
    private boolean finished = false;  
    private ArrayList<String> tasks = new ArrayList<String>();
    private Random rand;
    private double rkey;

    public static void main(String[] args){

    //pithano lathos
        try {
            Master m = new Master(args);
        } catch (Exception exc) {  }
    }

    Master (String[] args){
        rand = new Random();
        String url="";
        String s1="",s2="",s3="",myLine="",key="";
        File myFile=null;
        File imgFile = null;
        String myFileName="";
        String myFileName2="";
        StringTokenizer st;
        BufferedReader br=null;
        int numoftokens = 0;
        int endframe = 0;
        int degrees = 0;
        int eikona = 001;
        int i;
        double scale = 1.0;
        byte[] imageInByte = null;
        imageData imdat = null;
        imageResult imres = null;
        Boolean registered = false;

        //Register to ITaskbag

        try {  //try 1  
            //try to register 
            tb = (ITaskBag1) Naming.lookup(name);
        }
    }
}

Server:

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.LocateRegistry;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;

public class TaskBagServer{ 

    public static void main(String args[]) {
        final int DEFAULT_PORT = 1099;
        String sport="";
        int port=DEFAULT_PORT;
        String connectionstring="//127.0.0.1/TaskbagServer";
        //String porterror = "Invalid port specified, " + DEFAULT_PORT + " assumed";
        try {
            //LocateRegistry.createRegistry(1099);
            // connectionstring = "//127.0.0.1:"+port+"/TaskbagServer";
            java.rmi.registry.LocateRegistry.createRegistry(1099);    
        } catch (RemoteException ex) {
            Logger.getLogger(TaskBagServer.class.getName()).log(Level.SEVERE, null, ex);
        }       
        try {
            TaskBag1 server = new TaskBag1();
            Naming.rebind("connectionstring",server);
            System.out.println("Taskbag Server Bound");
        }
    }
}
4

3 回答 3

1

我认为问题在于您在服务器的调用中引用了connectionstring变量。Naming.rebind()这会将 URL 设置为connectionstring而不是您真正想要的。

于 2013-07-14T21:51:48.380 回答
0

[删除引号后]:检查拼写。您同时拥有 TaskBagServer 和 TaskbagServer。

我使用远程接口的类名作为绑定名,即在本例中为 ITaskBag1.class.getName()。它消除了这种拼写错误的问题,如果你弄错了它不会编译,它还解决了唯一性问题。

于 2013-07-14T22:17:45.407 回答
0

你在这里做什么?

try {
    TaskBag1 server = new TaskBag1();
            Naming.rebind("connectionstring",server);
    System.out.println("Taskbag Server Bound");
}

“connectionstring”将是重新绑定的 URI……你应该写它而不用“”,因为你想引用一个字符串。
顺便说一句:您应该在该字符串中使用前缀“rmi:”。

于 2013-07-14T21:56:14.710 回答