Forums Register Login

I am getting null value insted of system information.

+Pie Number of slices to send: Send
Hello Sir,

I want to get Server System Information on client machine. I am getting null value. I am sending my code here with. Please check it and tell me What's the problem with this code?

(1) Interface:

//CountRMI.java

public interface CountRMI extends java.rmi.Remote {
public int getSum() throws java.rmi.RemoteException;
public void setSum(int val) throws java.rmi.RemoteException;
public int increment() throws java.rmi.RemoteException;
public String getProperties() throws java.rmi.RemoteException;
}

(2) Implementation:

// CountRMIImpl.java

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.awt.*;
import java.lang.*;

public class CountRMIImpl extends UnicastRemoteObject implements CountRMI
{
private int sum;
private String finalString,name,ver,user,lang,reg,cpu,jname,vmname,VmVen,VmVer,venurl;

public CountRMIImpl(String name) throws RemoteException
{

super();

try
{
Naming.rebind(name, this);
sum = 0;
finalString = ("\n\n\nSystem :\n "+name+"\n Version "+ver+"\n\n"+"Registered To :\n User "+user+"\n Language "+lang+"\n Region "+reg+"\n\n"+"Computer :\n "+cpu+"\n\n"+"Java Information :\n "+jname +"\n "+vmname+"\n "+VmVen+"\n Version "+VmVer+"\n "+venurl);
}

catch (Exception e)
{
System.out.println("Exception "+e.getMessage());
e.printStackTrace();
}
}

public int getSum() throws RemoteException
{
return sum;
}

public void setSum(int val) throws RemoteException
{
sum = val;
}

public int increment() throws RemoteException
{
return sum++;
}

public String getProperties() throws RemoteException
{
return finalString;
}

}

(3) Client Class:

//CountRMIClient.java

import java.io.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.lang.*;
import java.net.*;

public class CountRMIClient
{
public static void main(String [] args)
{
String[] s = new String[25];
String[] str = new String[25];
FileReader fr;
FileWriter fw;
PrintWriter pw;
BufferedReader br;
int lineNo=0,noLines;

try
{
fr = new FileReader("IPList.txt");
br = new BufferedReader(fr);

while((s[lineNo]=br.readLine()) != null)
lineNo++;

br.close();
fr.close();
}

catch(FileNotFoundException fnfe)
{
System.out.println("File not found.... try another");
}

catch(IOException ioe)
{
System.out.println("I/0 Exception while reading file");
}

while(true)
{
noLines = 0;

for( int j = 0; j < lineNo; j++)
{
try
{
CountRMI myCount = (CountRMI)Naming.lookup("rmi://"+s[j]+"/mycount");

str[noLines] = s[j];
noLines++;

// Set Sum to intial value of 0.

System.out.println("Setting Sum to 0");
myCount.setSum(0);

// Calculate Start time.

long startTime = System.currentTimeMillis();

// Increment 1000 times

System.out.println("Incrementing");

for(int i = 0; i < 1000; i++)
{
myCount.increment();
}

// Calaculate stop time; print out statistics.

long stopTime = System.currentTimeMillis();

System.out.println("Average Ping = "+ ((stopTime - startTime)/1000f) +" micro-second");
System.out.println("Sum = "+myCount.getSum());
System.out.println("Server "+s[j]+" is working");
System.out.println(myCount.getProperties());
System.out.println();
}

catch(RemoteException re)
{
System.err.println("Server "+s[j]+" is not ready.");
System.out.println();

}

catch(NotBoundException nb)
{
System.err.println(" File Not Found "+nb);
}

catch(MalformedURLException mfue)
{
System.err.println(" Proble with URl Change and try again....");
}
}

try
{
// Creating File for Working Server.

fw = new FileWriter("OnList.txt");
pw = new PrintWriter(fw);

for(int k = 0; k < noLines; k++)
pw.println(str[k]);

fw.close();
pw.close();
}

catch(IOException ie)
{
System.err.println(" File Not Found "+ie);
}

try
{
System.out.println("Wait Few Seconds..........");
System.out.println();
Thread.sleep(18000);
}

catch(InterruptedException ie)
{
System.out.println("Interrupted the sleep...");
}
}
}
}

(4) Server Class:

// CountRMIServer.java

import java.rmi.*;
import java.rmi.server.*;
import java.awt.*;
import java.lang.*;

public class CountRMIServer
{
public static void main(String [] args)
{
//Create and Install the security manager

try
{
CountRMIImpl myCount = new CountRMIImpl("mycount");
System.out.println("CountRMI Server ready.");

String name = System.getProperty("os.name");
String ver = System.getProperty("os.version");
String user = System.getProperty("user.name");
String lang = System.getProperty("user.language");
String reg = System.getProperty("user.region");
String cpu = System.getProperty("sun.cpu.isalist");
String jname = System.getProperty("java.runtime.name");
String vmname = System.getProperty("java.vm.name");
String VmVen = System.getProperty("java.vm.vendor");
String VmVer = System.getProperty("java.vm.version");
String jclass = System.getProperty("java.class.version");
String venurl = System.getProperty("java.vendor.url");

}

catch(Exception e)
{
System.out.println("Exception: "+e.getMessage());
e.printStackTrace();
}
}
}

Please, check my code and replay me.

Thanking You
Yatin
+Pie Number of slices to send: Send
The problem looks like your CountRMIServer and CountRMIImpl classes aren't finished. CountRMIServer gets all the properties using System.getProperties(), but it never passes these values into the CountRMIImpl class. CountRMIImpl doesn't even have any methods to set these values - it just has class level attributes, which are never assigned a value (which explains why you are getting null. You'll either need to pass all the property values into the CountRMIImpl constructor, or you'll need to get all the values using System.getProperties() inside the CountRMIImpl constructor rather than in the CountRMIServer.
It's exactly the same and completely different as this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1321 times.
Similar Threads
I need help to create exe file.
Problem with RMI code?
File Not Bound java.rmi.NotBoundException
Unable to find Skeleton in the rmi invokation
RMI HELP -- URGENT
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:23:56.