Zdalny port wywołania metody w użyciu

Stworzyłem program typu Serwer, Klient z RMI. Ale za każdym razem, gdy uruchamiam mój serwer po uruchomieniu rmiregistry z wiersza polecenia, błąd portu jest wyrzucany. To tylko ja Zacząłem rmiregistry. Sprawdziłem to z netstat.

Kod Serwera:

public class Server implements Runnable, Linker{


private static Server server = null;
    private static Linker l = null;
    private String name = null;
    public Server(){}

    public void setName(String name){
        this.name = name;
    }
    public String getName(){
        return name;               
    }  
    public void run(){
        while(!("Andy").equalsIgnoreCase(name)){

        }
    }
    public static void createStub(){
        try{
            server = new Server();
            l = (Linker) UnicastRemoteObject.exportObject(server, 1099);

            Registry registry = LocateRegistry.getRegistry();
            registry.bind("Link", l);
            System.out.println("Ready");
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }                       
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        createStub();
        Thread t = new Thread(server);

    }
}

Kod Klienta:

public class Client implements Runnable{


private Scanner sc = new Scanner(System.in);
    private Linker linker = null;

    public void loadStub(){
        try{
            Registry registry = LocateRegistry.getRegistry(1099);
            linker = (Linker) registry.lookup("Link");

        }catch(Exception e){

        }
    }
    public void run(){
        String ip = null;
        while(sc.hasNext()&&!(ip = sc.nextLine()).equalsIgnoreCase(":q")){
            try {
                linker.setName(ip);
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }


    public static void main(String...args){
        Client client = new Client();
        client.loadStub();
        Thread t = new Thread(client);
        t.start();
    }
}

Wyjątek:

java.rmi.server.ExportException: Port already in use: 1099; nested exception is: 
java.net.BindException: Address already in use: JVM_Bind
Author: maja, 2011-12-01

6 answers

rmiregistry używa portu 1099 w swoim procesie, więc nie możesz go użyć w swoim. Albo:

  1. Uruchom rejestr w tym samym procesie, poprzez LocateRegistry.createRegistry() (preferowane).
  2. Eksportuj obiekt na innym porcie.
  3. Uruchom rmiregistry Na innym porcie niż 1099.
 7
Author: user207421,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-11-04 04:31:55

Jeśli używasz macOS, możesz zatrzymać port następujący jak:

Pierwsza rzecz, którą musisz znaleźć PID_number: lsof -i :1099

A następnie Zabij ten port: kill -9 PID_number

 44
Author: Tai Le,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-21 04:55:29

Użyj tego kodu serwera -

Registry registry = null;
try {
    registry = LocateRegistry.getRegistry(52365);//use any no. less than 55000
    registry.list();
    // This call will throw an exception if the registry does not already exist
}
catch (RemoteException e) { 
    registry = LocateRegistry.createRegistry(52365);
}
 7
Author: anirudha mundada,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-01 09:13:15

Sprawdź ponownie, czy port 1099 nie jest używany przez żaden inny proces lub użytkownika lub uruchom rmiregistry na innym porcie.

 0
Author: Gaurav,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-01 06:22:25

Użyj ps-aef / grep rmiregistry. znajdź pid, którego używa rmiregistry. Kill the pid Den uruchom ponownie serwer...!!!!

 0
Author: user3796191,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-07-05 11:34:27

Spróbuj tego:

lsof -P | grep ':1099' | awk '{print $2}' | xargs kill -9
 0
Author: Arif Acar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-28 10:30:52