RMI Client code Connection problem

Hi all,

I am new to Java RMI programming, so excuse me for stupid question

Problems:

i am not using Application server

-My Remote interface is like this

package Test;

import java.awt.Image;

import java.rmi.Remote;

import java.rmi.RemoteException;

import java.util.Vector;

publicinterface Myinterfaceextends Remote{

publicint getSum(int a,int b)throws RemoteException;

public Vector databaseinteraction()throws RemoteException;

}

-My Server program is as follows

package Test;

import java.awt.Image;

import java.rmi.Naming;

import java.rmi.RemoteException;

import java.rmi.server.UnicastRemoteObject;

import java.sql.DriverManager;

import java.sql.Connection;

import java.util.Vector;

import com.mysql.jdbc.ResultSet;

import com.mysql.jdbc.Statement;

publicclass Myserverextends UnicastRemoteObjectimplements Myinterface{

static Statement stmt =null;

static ResultSet result =null;

privatestaticfinallong serialVersionUID = 1;

protected Myserver()throws RemoteException{

super();

}

publicstaticvoid main(String[] args)throws RemoteException{

Myserver server =new Myserver();

try{

Naming.rebind("rmi://192.168.1.24/Myserver",server);

System.out.println("I m registered");

}

catch(Exception e){

System.out.println(e);

}

}

publicint getSum(int a,int b)throws RemoteException{

return a+b;

}

public Vector databaseinteraction()throws RemoteException{

try{

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?"+"user=root");

stmt = (Statement) conn.createStatement();

result = (ResultSet) stmt.executeQuery("select * from test1");

Vector results =new Vector();

while (result.next()){

results.add(result.getString(1));

}

conn.close();

return results;

}

catch(Exception e){

System.out.println(e);

}

returnnull;

}

}

Myclient code is as follows

import java.net.MalformedURLException;

import java.rmi.Naming;

import java.rmi.NotBoundException;

import java.rmi.RemoteException;

import java.util.Vector;

import java.net.*;

publicclass Myclient{

publicstaticvoid main(String[] args)throws MalformedURLException, RemoteException, NotBoundException{

try{

System.setProperty("java.security.policy","client.policy");

System.setSecurityManager(new RMISecurityManager());

Myinterface server = (Myinterface) Naming.lookup("rmi://192.168.1.24/Myserver");

int result=server.getSum(2,3);

System.out.println("Result:"+result);

Vector resultsvector = (Vector)server.databaseinteraction();

for(int i=0; i < resultsvector.size(); i++){

System.out.println(resultsvector.get(i));

}

}

catch(Exception e){

System.out.println(e);

}

}

}

Client.policy code is

grant

{

permission java.net.SocketPermission

"*:1024-65535","connect";

};

When i try to run the Client program from remote machine its not working

it says

Error

Myinterface cannot be resolved to a type

Please! let me know what i can do to run this code from remote machine

[7363 byte] By [Vklinuxa] at [2007-10-2 22:07:32]
# 1
Are you sure that's the error message?You need MyInterface.class deployed at the client, and if you are using < JDK 1.5 you also need MyServer_Stub.class deployed at the client.
ejpa at 2007-7-14 1:24:16 > top of Java-index,Core,Core APIs...
# 2
I have created stub and started rmiregistry using rmic Test.Myserverstart rmiregistryon m/c where server program is running should i have to do something at Client m/c also for Client codeLet me know about it
Vklinuxa at 2007-7-14 1:24:16 > top of Java-index,Core,Core APIs...
# 3
I already have in reply #1. Is there something there you don't understand?
ejpa at 2007-7-14 1:24:16 > top of Java-index,Core,Core APIs...
# 4
I din't get it
Vklinuxa at 2007-7-14 1:24:16 > top of Java-index,Core,Core APIs...
# 5
ok now i have copied Myinterface.java file at client sidewhile compiling "Myclient" i got following errorjava.lang.ClassCastException: Test.Myserver_StubLet me wht can i do more
Vklinuxa at 2007-7-14 1:24:16 > top of Java-index,Core,Core APIs...
# 6
You really got that while compiling?
ejpa at 2007-7-14 1:24:16 > top of Java-index,Core,Core APIs...
# 7

It was my mistake anyways i solved it

i was able to sucessfully run that code on local m/c

but when i tried to run the same on other m/c i got an exception saying

java.lang.ClassNotFoundException: Myserver_stub (i.e. stub class not found)

i appreciate ur Patience ,but if u can help please help me

Vklinuxa at 2007-7-14 1:24:16 > top of Java-index,Core,Core APIs...
# 8
There is enough information in that exception and its text message for you to solve it by yourself actually.
ejpa at 2007-7-14 1:24:16 > top of Java-index,Core,Core APIs...
# 9
Your error would solve your problem !Just copy the _Stub file on the remote machine, thats all !!
siddhsdesaia at 2007-7-14 1:24:16 > top of Java-index,Core,Core APIs...
# 10
Thanx a lot it solved my problem
Vklinuxa at 2007-7-14 1:24:16 > top of Java-index,Core,Core APIs...