Check if your port 1099 is accessible (this means that it is blocked by a firewall). In addition, you did not mention which OS you are using, and whether you ran the registry before starting your server.
This RMI tutorial explains:
Before starting the computing engine, you need to run the RMI registry. The RMI registry is a simple server-side bootstrap naming facility that allows remote clients to get a link to the source remote object.
By default, the registry runs on port 1099, as you have. As the tutorial reports, simply open a command prompt (on Windows) or a shell terminal (on a UNIX-like OS) and enter:
For Windows (use javaw if launch is not available):
start rmiregistry
Solaris or Linux OS :
rmiregistry &
UPDATE
After training Oracle and my project at that time, I noticed that in the Server
class you did not export the object at runtime RMI. Then you should edit these lines:
Controle obj = new Controle(4); Registry reg = LocateRegistry.createRegistry(1099); System.out.println("Server is ready"); reg.rebind("CtrlServ", obj);
so that:
Controle obj = new Controle(4); Controle stub = (Controle) UnicastRemoteObject.exportObject(obj, 0); Registry reg = LocateRegistry.createRegistry(1099); System.out.println("Server is ready"); reg.rebind("CtrlServ", stub);
Because the tutorial reports:
The UnicastRemoteObject.exportObject static method exports the provided remote object so that it can receive calls to its remote methods from remote clients.
In addition, if you use the same host to call RMI, it is not needed in the Client
class:
Registry registry = LocateRegistry.getRegistry("localhost");
Just call:
Registry registry = LocateRegistry.getRegistry();
Because Oracle reports:
Overload with no arguments LocateRegistry.getRegistry synthesizes a registry link on the local host and on the default registry port, 1099. You must use the overload with the int parameter if the registry is created on a port other than 1099.