|
Duplicate :
|
|
|
Relates :
|
|
|
Relates :
|
If a remote object is exported by a call to
UnicastRemoteObject.exportObject(obj, port), and later unexported
by a call to UnicastRemoteObject.unexportObject(obj, true), the port is still
being used.
The following code shows the problem:
import java.rmi.registry.LocateRegistry;
import java.io.*;
import java.rmi.server.*;
import java.net.*;
import java.rmi.*;
public class ExportTest {
public static void main(String[] args) throws Exception {
int port = 10001;
ExpObj obj = (ExpObj) new ExpObjImpl();
UnicastRemoteObject.exportObject(obj, port);
UnicastRemoteObject.unexportObject(obj, true);
try {
ServerSocket s = new ServerSocket(port);
} catch (IOException e) {
System.out.println("Got an exception in creating ServerSocket");
e.printStackTrace();
}
}
}
interface ExpObj extends java.rmi.Remote {
}
class ExpObjImpl implements ExpObj {
public ExpObjImpl() throws RemoteException {}
}
The output is:
Got an exception in creating ServerSocket
java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:397)
at java.net.ServerSocket.<init>(ServerSocket.java:170)
at java.net.ServerSocket.<init>(ServerSocket.java:82)
at ExportTest.main(ExportTest.java:14)
|