Ok,
Here goes im pretty new to java, but need to compile and run the following code. It's basicially a RMI Client Server which generates prime numbers
Here is the source Code
CLIENT
import java.rmi.Naming; import java.rmi.RemoteException; import java.net.MalformedURLException; import java.rmi.NotBoundException; import java.io.*; public class PrimesClient { public static void main(String[] args) { try { if (args.length != 3) { System.out.println("Error usage: java PrimesClient host " +" min max"); System.exit(0); } //look up the service in the registry Primes c = (Primes) Naming.lookup("rmi://" + args[0] + "/PrimesServd"); int ct; int lct = 0; int min = Integer.parseInt(args[1]); int max = Integer.parseInt(args[2]); int[] p = c.findPrimes(min, max); ct = p[0]; for (int i = 1; i < ct; i++) { lct++; if (lct == 12) { lct = 0; System.out.println(); } System.out.print(" " + p[i]); } System.out.println(); } catch (Exception e) { System.out.println("Exception" + e); System.out.println(e); } } }
This is the error I receive in JCreator for Client Part
C:\Users\Tevez aka Ratman\Desktop\PrimesClient.java:19: cannot find symbol
symbol : class Primes
location: class PrimesClient
Primes c = (Primes) Naming.lookup("rmi://" + args[0] +
^
C:\Users\Tevez aka Ratman\Desktop\PrimesClient.java:19: cannot find symbol
symbol : class Primes
location: class PrimesClient
Primes c = (Primes) Naming.lookup("rmi://" + args[0] +
^
2 errors
Process completed.
SERVER
import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.RMISecurityManager; import java.rmi.server.UnicastRemoteObject; import java.rmi.registry.LocateRegistry; public class PrimesServd extends UnicastRemoteObject implements Primes { int[] p; public PrimesServd() throws RemoteException { super(); p = new int[1000]; } public int[] findPrimes(int min, int max) throws java.rmi.RemoteException { int ct = 1; for (int i = min; i < max; i++) { if (isPrime(i)) { p[ct] = i; ct++; } } p[0] = ct; return p; } private static boolean isPrime(int n) { int i; for (i = 2; i * i <= n; i++) { if ((n % i) == 0) { return false; } } return true; } public static void main(String args[]) { if (args.length != 1) { System.out.println("Error! correct usage java PrimesServd server-host"); } else { try { // Create and install a security manager //if (System.getSecurityManager() == null) { //System.setSecurityManager(new RMISecurityManager()); // } PrimesServd sc = new PrimesServd(); Naming.rebind("rmi://" + args[0] + "/PrimesServd", sc); System.out.println("PrimesServd bound in registry"); } catch (Exception e) { System.out.println(" Server err: " + e.getMessage()); } } } }
This is error I receive for client part
C:\Users\Tevez aka Ratman\Desktop\PrimesServd.java:46: unclosed string literal
System.out.println("Error! correct usage java
^
C:\Users\Tevez aka Ratman\Desktop\PrimesServd.java:46: ';' expected
System.out.println("Error! correct usage java
^
C:\Users\Tevez aka Ratman\Desktop\PrimesServd.java:47: unclosed string literal
PrimesServd server-host");
^
C:\Users\Tevez aka Ratman\Desktop\PrimesServd.java:47: not a statement
PrimesServd server-host");
^
C:\Users\Tevez aka Ratman\Desktop\PrimesServd.java:56: ';' expected
RMISecurityManager());
^
5 errors
Process completed.
Please could someone please tell me why its not functioning