RMI Server on Linux

hi,

I'm using Fedora Core 4 linux.

The code below transfers a file from client to server.

When i make windowsXP as my RMI server n Linux as my RMI Client, the code works perfectly (as in the file is copied from linux to windowsXP)

But does not work the other way. ( When i make linux as RMIServer n WindowsXP as RMI Client)

RMIClient

public static void main(String args[]) //java RMIClient 192.168.0.2 file.jar

{

/*

*my file copying code

*filename =args[1];

*Server IP Address=args[0];

*"bytes" has file content

*/

String RemoteServerURL = "rmi://" + args[0] + "/RemoteServer";

Store store =(Store)Naming.lookup(RemoteServerURL);

store.retFname(filename);

store.sendJar(bytes);

}

-

Remote Server

public static void main(String args[])

{

StoreImpl storeImpl= new StoreImpl();

Naming.rebind("RemoteServer",storeImpl);

}

-

NOTE:

While compiling or while executing ,the codes give no error/exceptions.

[1074 byte] By [snap_shaha] at [2007-11-26 23:57:13]
# 1
If there is no error, then what do you mean by "does not work"?
genadya at 2007-7-11 15:43:48 > top of Java-index,Core,Core APIs...
# 2
the file ( filename =args[1]) is not copied on Linux.Message was edited by: snap_shah
snap_shaha at 2007-7-11 15:43:48 > top of Java-index,Core,Core APIs...
# 3
snap_shah, this is a forum, not a guessing game.You haven't shown us what the Store interface looks like; what the implementations of the remote methods look like; or what the code that assembles the byte[] in the client looks like.How could anyone anywhere possibly help?
ejpa at 2007-7-11 15:43:48 > top of Java-index,Core,Core APIs...
# 4

//-RemoteServer-

import java.rmi.Naming;

public class RemoteServer

{

public static void main(String args[])

{

try

{

StoreImpl storeImpl= new StoreImpl();

Naming.rebind("RemoteServer",storeImpl);

}

catch(Exception e)

{

//System.out.println("Exception: " + e);

}

}

}

//RemoteClient-

//Client side

import java.io.File;

import java.io.FileInputStream;

import java.rmi.Naming;

public class RMIClient

{

public static void main(String args[])

{

FileInputStream fs;

byte[] bytes;

File file;

String filename=args[1];

file=new File("c://Collectors//"+filename);

try

{

fs=new FileInputStream(file);

long length = file.length();

bytes= new byte[(int)length];

if (length > Integer.MAX_VALUE)

{

System.out.println("File size too large.");

}

int offset = 0;

int numRead = 0;

while(offset < bytes.length && (numRead=fs.read(bytes, offset, bytes.length-offset)) >= 0)

{

offset += numRead;

}

if (offset < bytes.length)

{

}

fs.close();

System.out.println("File Downloaded..");

String RemoteServerURL = "rmi://" + args[0] + "/RemoteServer";

Store store =(Store)Naming.lookup(RemoteServerURL);

store.retFname(filename);

store.sendJar(bytes);

}

catch(Exception e)

{}

}

}

//--Interface>Store--

import java.rmi.Remote;

import java.rmi.RemoteException;

public interface Store extends Remote

{

public void retFname(String filename)throws RemoteException;

public void sendJar(byte[] bytes) throws RemoteException;

}

//Implementation --> StoreImpl-

import java.io.File;

import java.io.FileOutputStream;

import java.rmi.RemoteException;

import java.rmi.server.UnicastRemoteObject;

public class StoreImpl extends UnicastRemoteObject implements Store

{

static final long serialVersionUID =1;

String fname;

public StoreImpl() throws RemoteException

{

}

public void retFname(String filename) throws RemoteException

{

fname=filename;

}

public void sendJar(byte[] bytes) throws RemoteException

{

try

{

File file1;

if(fname.startsWith("win"))

file1=new File("c://Collectors//"+fname);

else

file1=new File("/Collectors/"+fname);

FileOutputStream fos=new FileOutputStream(file1);

fos.write(bytes,0, bytes.length);

fos.close();

}

catch(Exception e)

{

}

}

}

Message was edited by:

snap_shah

snap_shaha at 2007-7-11 15:43:48 > top of Java-index,Core,Core APIs...
# 5

Well apart from the fact that you're still testing the length of the file a line too late, you can't possibly know whether your code throws any exceptions. Your catch blocks don't log or print out the exception. You have this in the client:

catch(Exception e)

{}

and this in the server:

catch (Exception exc)

{

}

You will find that you did indeed get an exception somewhere.

Never ignore an exception. In this case the sendJar method should probably be declared to throw IOException as well as RemoteException, and the exception shouldn't be caught on the server side at all.

ejpa at 2007-7-11 15:43:48 > top of Java-index,Core,Core APIs...