dcsimg
How to transfer InputStream between RMI Server and Client
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   kang_gongzi
Posted On:   Tuesday, October 23, 2001 07:25 AM

I want to transfer InputStream between RMI.Client will get InputStream from Server and use it just like local InputStream. Here is what I do in Server side: public interface RemoteInputStreamHandle extends Remote { public int read(byte[] b) throws IOException, RemoteException; public void close() throws IOException, RemoteException; ... } public class RemoteInputStreamHandleImpl extends UnicastRemoteObject implements RemoteInputStreamHandle { private InputStream is = null; public RemoteInputStreamHandleImpl (InputStream is) throws RemoteException { super(); this.is = is; } public int read (byte[] b) t   More>>
			
I want to transfer InputStream between RMI.Client will
get InputStream from Server and use it just like local
InputStream.

Here is what I do in Server side:

public interface RemoteInputStreamHandle extends Remote {
public int read(byte[] b) throws IOException, RemoteException;
public void close() throws IOException, RemoteException;
...
}
public class RemoteInputStreamHandleImpl
extends UnicastRemoteObject
implements RemoteInputStreamHandle {
private InputStream is = null;
public RemoteInputStreamHandleImpl (InputStream is)
throws RemoteException {
super();
this.is = is;
}
public int read (byte[] b)
throws IOException, RemoteException {
return is.read(b);
}
...
}
public class RemoteInputStream extends InputStream
implements Serializable{
private RemoteInputStreamHandle ris = null;
public RemoteInputStream(RemoteInputStreamHandle ris)
throws RemoteException{
this.ris = ris;
}
public int read (byte[] b)
throws IOException, RemoteException{
return ris.read(b);
}
...
}

When I get RemoteInputStream(a valid file and has content) from
Server,and call it's read(byte[] b) method like:
...
InputStream remoteInputStream = server.getInputStream();
byte[]content = new byte[1024];
int len = remoteInputStream.read(content);
...
The result is that 'len' is correct(the true length of the file
which <1024), but what's in 'content' is nothing. I have no sense
of it. What happans?

Additionally, OutputStream implemented like above excutes correctly.
   <<Less

Re: How to transfer InputStream between RMI Server and Client

Posted By:   ryan_wexler  
Posted On:   Thursday, October 25, 2001 11:05 AM

I will take a stab at this. My first thought would be that you can not pass input or output streams from client to server or vice versa because of security. But even if it allows you to then when it tries to read or write to the stream it probably can't find it because it is not local anymore. Why would you want to pass a stream like that? Can I guess because the file is not available to the client. So you are opening a stream on the server side and then passing it to the client to read from. Instead of doing that why not just pass the data you are reading rather then the stream. or am I not following you?
About | Sitemap | Contact