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 t
Use this Server code -
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);
}
If you're using macOS, you can stop port following as:
First thing you need to find the PID_number: lsof -i :1099
And then kill that port: kill -9 PID_number
Try this:
lsof -P | grep ':1099' | awk '{print $2}' | xargs kill -9
Re-check if the port 1099 is not used by any other process or user or start the rmiregistry on some other port.
The rmiregistry
is using port 1099 in its process so you can't use it in yours. Either:
LocateRegistry.createRegistry()
(preferred).rmiregistry
on a different port other than 1099.Use ps -aef |grep rmiregistry. find the pid which rmiregistry use. Kill the pid Den run the server again...!!!!