The moose likes Distributed Java and the fly likes Dynamic Class Downloading From an HTTP Server Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Distributed Java
Reply Bookmark "Dynamic Class Downloading From an HTTP Server" Watch "Dynamic Class Downloading From an HTTP Server" New topic
Author

Dynamic Class Downloading From an HTTP Server

mridul das
Greenhorn

Joined: Jul 15, 2005
Posts: 19
I am pretty new to RMI. I have a simple HTTP sever(found in the net) whic serves the classes to the client through a server socket as follows
out.writeBytes("HTTP/1.0 200 OK\r\n");
out.writeBytes("Content-Length: " + bytecodes.length +
"\r\n");
out.writeBytes("Content-Type: application/java\r\n\r\n");
out.write(bytecodes);
out.flush();

While I try this from the same machine
Class cls1 = RMIClassLoader.loadClass(new URL("http://machine-name:2001/"),"className");
the class seems to be loaded.
But the same code on trying from a different machine gives the following exception
java.lang.ClassNotFoundException: jnp.server.Test_Stub
at java.net.URLClassLoader$1.run(URLClassLoader.java:196)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:430)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:631)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:169)
at Main.test(Main.java:55)
at Main.main(Main.java:33)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:222)
at java.io.BufferedInputStream.read(BufferedInputStream.java:277)
at sun.net.www.MeteredStream.read(MeteredStream.java:106)
at java.io.FilterInputStream.read(FilterInputStream.java:111)
at sun.misc.Resource.getBytes(Resource.java:64)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
... 13 more
Could anyone help me understand what the prob is .
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35439
    
    9
Caused by: java.net.SocketException: Connection reset

This is the root cause. Are you certain that you can connect to port 2001 on the server from the machine that's giving you problems? Are there any error messages in the server log?


Android appsImageJ pluginsJava web charts
mridul das
Greenhorn

Joined: Jul 15, 2005
Posts: 19
I commented out a peice of code which was
finally{
socket.close();
}
Since then it seems to be working.
But havent found the answer to why was it working in the local machine. The stub was not in the classpath however
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Class Downloading From an HTTP Server
 
Similar Threads
rmi Unknown host
Dynamic Class Downloading Simple Question
cant run java file from command line but works with .sh file??
NX: Execute runme.jar with RMI
problem with rmi