aspose file tools*
The moose likes Distributed Java and the fly likes rmiregistry programmatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "rmiregistry programmatically" Watch "rmiregistry programmatically" New topic
Author

rmiregistry programmatically

Rob Qas
Ranch Hand

Joined: Apr 10, 2006
Posts: 34
hello,

I am having problems when I turn on the rmiregistry programmatically... using LocateRegistry.CreateRegistry.

My RMI servers bind successfully to the registry. However, when I try to connect to these servers, I get



What could be the problem?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

What URL are you using in Naming.lookup()?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Rob Qas
Ranch Hand

Joined: Apr 10, 2006
Posts: 34
rmi://localhost:1099/dataSource
Rob Qas
Ranch Hand

Joined: Apr 10, 2006
Posts: 34
i started the server with this code



but when i check netstate -a thers no lisiner on port 1099
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Are you on Windows?

try a

netstat -a

from the command prompt. This will at least tell you if the port your listening on is open. Looks like it just can't make the connection.

OPEN THOSE PORTS!!!
Rob Qas
Ranch Hand

Joined: Apr 10, 2006
Posts: 34
yes iam using windows..

i tried netstat -a and its not listing to the port i dont why!!
when i run the rmiregistry from the command promt i dont got any problems but if i run it programaticly its not working ..
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Is there any code keeping your server alive?

It could be creating your server object, starting the registry, binding your server, and then just exiting - the registry would just die with the rest of your code.
tariq shadid
Greenhorn

Joined: Jul 31, 2006
Posts: 11
hello
please test this code if you need to solve your problem


public static void main(String[] args) throws Exception
{
try
{
remoteServer server = new remoteServerImpl();
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
System.setProperty(Context.PROVIDER_URL, "rmi://localhost:1099");
Registry registry = LocateRegistry.createRegistry(1099);
remoteServer stub = (remoteServer) UnicastRemoteObject.exportObject(server,1099);
registry.rebind ("dataSource", stub);
JOptionPane.showMessageDialog(null,"##### SERVER STARTED #####");
System.out.println("##### SERVER STARTED #####");
}
catch (Exception e)
{
}
}
TARIQ SHADID
WEB DEVELOPER
Rob Qas
Ranch Hand

Joined: Apr 10, 2006
Posts: 34
so how can i keep my server alive? please if you can send me a sample code for doing this .. thanks for your help
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

All you have to do is create a new thread and start it.

Normally this isn't a problem because the server won't die as long as there are remote references to it - and normally the RMI Naming service fulfills that - but since you are starting the naming server in the same JVM - there are no remote references to it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: rmiregistry programmatically