• Post Reply Bookmark Topic Watch Topic
  • New Topic

rmi when i running client and server that is ondifferent machine

 
Anu katoch
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
i am new to java networking, please check the code and also gide me where to keep my client server stub and interface and anything i have to add in my classes....

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version n
umber in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
My server
package BIConsulting.java;
import java.io.*;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Map;
import java.rmi.server.UnicastRemoteObject;
import java.util.Set;
import java.util.Iterator;

public class Bserver extends UnicastRemoteObject implements BInt
{
public Bserver()throws RemoteException{
super();
}
String error = null;
String output = null;

public String getError()
{
return error;
}

public String getOutput()
{
return output;
}

/** Called from inside the jsp like new Console().exec("cscript drucken.vbs param1 param2") **/
public int exec(){
int exitVal=9999 ;
try{


int count=0;

int Valuecnt=0;
Map map = System.getenv();
Set keys = map.keySet();
Iterator iterator = keys.iterator();
String key =null;
String value = null;

while (iterator.hasNext())
{
key = (String) iterator.next();
if (key.toLowerCase().equals("bicpath"))
{
value = (String) map.get(key);



count=count+1;
break;
}
}
if(count!=1)
{

Valuecnt=0;
}


if (value == null)
{

Valuecnt=0;
}


if (value.length() == 0)
{

Valuecnt=0;
}



boolean exists = (new File(value)).exists();
if (exists)
{

// System.out.println("Exists");
Valuecnt=1;

}
else
{
// System.out.println("Does not Exists");
Valuecnt=0;

}

if (count == 1)
{

if (Valuecnt== 1)
{

String osName = System.getProperty("os.name" );
String[] cmd = new String[3];
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2]=value+"\\BICEXE.exe";


// cmd[2]="E:\\NewFolder\\BICEXE.exe";

//cmd[2] = "C:\\windows\\notepad.exe";
//cmd[2] = "C:\\windows\\Console_JSP.exe";
//cmd[2] = "C:\\windows\\test.bat";
//cmd[2]="E:\\NewFolder\\test.bat";
// cmd[2]="E:\\NewFolder";
//cmd[4]="Console_JSP.exe";
//cmd[2]="E:\\NewFolder\\Console_JSP.exe";
//cmd[2]="E:\\NewFolder\\test.bat";

Runtime rt = Runtime.getRuntime();

//System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]);
Process proc = rt.exec(cmd);


exitVal = proc.waitFor();
// System.out.println(exitVal);

// any error message?
grabStream(proc.getErrorStream(), "error");

// any output?
grabStream(proc.getInputStream(), "output");

// any error???
//int exitVal = proc.waitFor();
//if (exitVal != 0)
// error += "ExitValue: "+exitVal;
}

}
}
catch (Exception e)
{
e.printStackTrace();
}






return exitVal;
}

private void grabStream(InputStream is, String msg)
{
if (!(msg.equals("error") || msg.equals("output")))
return;
String message = "";
try{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;

while ( (line = br.readLine()) != null)
message += line;
} catch (IOException ioe){
ioe.printStackTrace();
}
if (msg.equals("error"))
error = message;
else
output = message;

}
public static void main(String args[]) throws RemoteException, MalformedURLException{
//if(System.getSecurityManager()==null){
// System.setSecurityManager(new RMISecurityManager());

Bserver bi= new Bserver();
// bi.exec();
Naming.rebind("BInt",(Remote) bi);
System.out.println("services bound");
//}
}
}
My client:
package BIConsulting.java;
import java.rmi.Naming;

public class Bclient
{
public static void main(String args[]) throws Exception{
if (args.length != 1)
{
System.out.println
("Syntax - PowerServiceClient host");
System.exit(1);
}

// Assign security manager
//if (System.getSecurityManager() == null)
//{
// System.setSecurityManager
// (new RMISecurityManager());
//}

// Call registry for PowerService
BInt service = (BInt) Naming.lookup
("rmi://" + "ipaddress" + "/BInt");


System.out.println("number is"+service.exec());



}
}
my interface:
ackage BIConsulting.java;
import java.rmi.Remote;
import java.rmi.RemoteException;

/**
*
* @author anu.katoch
*/
public interface BInt extends Remote
{
public int exec()throws RemoteException;
}

i am also able to create stub Bserver_stub.class from server
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anu katoch wrote:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version n
umber in .class file


Welcome to the JavaRanch.
In the future, please use code tags so your code is readable.
Your error:

has nothing to do with RMI. A quick search will get you helpful advice like this page.
 
Anu katoch
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks my problem is resolved
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!