远程方法调用端口正在使用中 [英] Remote method invocation port in use

查看:134
本文介绍了远程方法调用端口正在使用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用RMI创建了一个服务器,客户端程序。但是,每当我从命令提示符启动rmiregistry后运行我的服务器,都会抛出已经使用的端口错误。它是唯一开始精神病的人。我已经从netstat检查了。



服务器代码:

  public class Server实现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);

注册表注册表= LocateRegistry.getRegistry();
registry.bind(Link,l);
System.out.println(Ready);
}
catch(异常e){
e.printStackTrace();
}
}
public static void main(String [] args){
// TODO自动生成的方法stub
createStub();
线程t =新线程(服务器);

}
}

客户端代码:

  public class客户端实现Runnable {


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

public void loadStub(){
try {
注册表注册表= 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 );
} catch(RemoteException e){
// TODO自动生成的catch块
e.printStackTrace();
}
}
}


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

异常:

  java.rmi.server.ExportException:端口已在使用:1099;嵌套异常是:
java.net.BindException:已经在使用的地址:JVM_Bind


解决方案

rmiregistry 正在使用1099端口,因此您无法使用它。或者:


  1. 通过LocateRegistry.createRegistry()(首选)在同一进程中启动注册表。


  2. 在1099以外的其他端口上启动 rmiregistry


I have created a Server, Client kind of program with RMI. But whenever I run my Server after starting the rmiregistry from command prompt, the port already in use error is thrown. Its only me who started the rmiregistry. I have checked it from netstat.

Server Code:

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

    }
}

Client Code:

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

Exception:

java.rmi.server.ExportException: Port already in use: 1099; nested exception is: 
java.net.BindException: Address already in use: JVM_Bind

解决方案

The rmiregistry is using port 1099 in its process so you can't use it in yours. Either:

  1. Start the registry in the same process, via LocateRegistry.createRegistry() (preferred).
  2. Export your object on a different port.
  3. Start the rmiregistry on a different port other than 1099.

这篇关于远程方法调用端口正在使用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆