启动在指定端口上运行的程序后,程序在客户端能够连接到该端口之前终止。
try {
StudentService obj = new StudentService();
Registry r = LocateRegistry.createRegistry(4200);
r.bind("localhost", obj);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AlreadyBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}这是位于已被重写的StudentService类中的方法。
int multiply(int s, int b) throws RemoteException {
return s * b;
}发布于 2017-04-07 23:35:05
从文件来看,
UnicastRemoteObject.exportObject导出提供的远程对象以在匿名TCP端口上接收传入的远程方法调用,并返回要传递给客户端的远程对象存根。
因此,您的程序在没有侦听传入连接的情况下结束是不足为奇的。这应该能行。
try {
StudentService obj = new StudentService();
UnicastRemoteObject.exportObject(obj, 0);
Registry r = LocateRegistry.createRegistry(4200);
r.bind("localhost", obj);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AlreadyBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}https://stackoverflow.com/questions/43288280
复制相似问题