Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

rmiregistry programmatically

 
Rob Qas
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What URL are you using in Naming.lookup()?
 
Rob Qas
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rmi://localhost:1099/dataSource
 
Rob Qas
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic