J.S
J.S

Reputation: 147

Rmi: Not Bound exception

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");
        }
    }
}

Upvotes: 1

Views: 12578

Answers (3)

user207421
user207421

Reputation: 310840

[After you remove the quotes]: Check your spelling. You have both TaskBagServer and TaskbagServer.

I use the class name of the remote interface as the bind name, i.e. in this case ITaskBag1.class.getName(). It eliminates this kind of problem with typos, as if you get it wrong it doesn't compile, and it also solves the uniqueness problem.

Upvotes: 0

Klumbe
Klumbe

Reputation: 380

what are you doing here?

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

"connectionstring" will be the URI to rebind...you should write it without the "", because you want to refer to a String.
By the way: you should use the prefix "rmi:" in that String.

Upvotes: 0

Qben
Qben

Reputation: 2623

I think the problem is that you quote the connectionstring variable in your Naming.rebind() call in the server. This will set the URL to connectionstring and not what you really want.

Upvotes: 1

Related Questions