[omniORB] Transfer a file using CORBA?
Glenn A. Hochberg
gah@research.att.com
Thu, 28 Dec 2000 09:20:03 -0500
Victor Chen wrote:
> Dear sir: dos anyone have any suggestion on transfer a binary file using CORBA? or you can give me a IDL example? I'know this is not a best method but I want to use in my project.
You would use a sequence<octet> to send the bytes through--that's the easy part. The trickier part is handling large files; you don't want to send them through in one chunk, as this
would be inefficient in terms of memory (the ORB has to buffer the whole message before sending). The typical solution would be to use iterators (see section 18.7 of Advanced CORBA
Programming with C++). You could use a "pull" iterator for retrieving files and a "push" iterator for sending files. For example:
typedef sequence<octet> FileChunk;
typedef unsigned short ChunkSize;
interface FileIterator {
FileChunk next(in ChunkSize how_much);
void destroy();
};
interface FileTransfer {
FileChunk get(in string fname, in ChunkSize how_much, out FileIterator ft);
void put(in string fname, in FileChunk first, in FileIterator ft);
...
};
When the client is getting a file, it tells the FileTransfer object on the server how big the first chunk should be--if the file is bigger than this, the server returns a non-nil
FileIterator reference along with the first chunk. In the case of put(), the client sends the first chunk, and if the file is bigger than is reasonable to send in one chunk, it sends
along its own FileIterator reference so that the server can retrieve the rest. In the put() case the client must also act as a server.
-Glenn
--
Glenn A. Hochberg | "Any activity becomes creative when the doer
AT&T Labs | cares about doing it right, or doing it better."
gah@research.att.com | -John Updike