Reputation: 25
I'm trying to distribute a simple room booking system that I implemented, I tried researching and this is what I came up with.. but When I run them and enter different port numbers the client still runs..shouldn't it only run if the port number matches the one I entered for Server? what did I do wrong?
For Client :
public static void main (String[] args)
{
Scanner s = new Scanner (System.in);
int portNum = 1099;//default port
try {
System.out.print("Enter the port number");
portNum= s.nextInt();
Registry reg= LocateRegistry.getRegistry("localhost", portNum);
System.out.println("Connected to RMI server");
For Server:
public static void main(String argv[]) {
int portNum = 1099;
try {
Scanner s = new Scanner (System.in);
HotelServer server = new HotelServer ();
//register it with the local naming registry
try
{
System.out.print("Enter The Port Number");
portNum= s.nextInt();
Registry reg= LocateRegistry.createRegistry(portNum);
reg.bind("localhost", server);
System.out.println("Server started");
Upvotes: 2
Views: 1161
Reputation: 310850
Just getting a result from LocateRegistry.getRegistry()
doesn't indicate that you're connected to anything. It doesn't perform any network operations. It just constructs a stub. If the port number isn't correct, you won't find out until you try to use it.
Upvotes: 1