You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@etch.apache.org by Prashant Shewale <pv...@gmail.com> on 2011/04/15 08:22:55 UTC

file transfer over the network

Hi,

       Is there built-in object type available in Etch for files (text as
well as binary), so that server can transfer file to client or vice-a-versa?
I thought of using External Type supported in Etch NSDL and declare language
specific file object. But it may cause a problem if I have client and
server implementations in different languages. Am I correct?

Can you please provide some clues on how to achieve this?

Thanks,
Prashant

Re: file transfer over the network

Posted by Prashant Shewale <pv...@gmail.com>.
Thanks Scott. In initial phase I want to send text file (of around 5KB) from
server to client. So I read it in byte[] and send that though function call
on client side.

On Fri, Apr 15, 2011 at 7:33 PM, scott comer <we...@mac.com> wrote:

> hi prashant,
>
> there is no builtin support for moving files. but you can easily do that
> yourself.
>
> different api needed perhaps, for text v. binary files.
>
> binary files just go over in chucks as a byte[], about 8k bytes at a time
> would do it. if you were into low-latency transfer of a single file, then
> you can double or triple buffer using async interface.
>
> text file read as string (using java's FileReader or InputStreamReader,
> taking care to select appropriate local CharSet). then transfer as chunks of
> string (eh, 4k or so at a time) (which will be utf-8 encoded and then
> decoded on the other end. at the other end, write the text file (using
> FileWriter or OutputStreamWriter with appropriate CharSet).
>
> we used an api sort of like this:
>
>        RemoteAccountDbServer server = BlahHelper.newServer(...);
>
>        ...
>
>        FileReader r = new FileReader("foobar.txt");
>
>        try {
>
>            String token = server.openFile("foobar.txt", "w");
>
>            try {
>
>                char[] buf = new char[4096];
>
>                int n;
>
>                while ((n = r.read(buf))>  0) {
>
>                    server.writeText(token,new String(buf, 0, n));
>
>                }
>
>            } finally {
>
>                server.closeFile(token);
>
>            }
>
>        } finally {
>
>            r.close();
>
>        }
>
>
> on the back-end you have to use token to locate the corresponding
> FileWriter and take care to clean up abandoned ones, and you have to add
> something that handles the error cases so that partially written files are
> expunged if necessary.
>
> where it matters, you might want to limit the number of file writers and /
> or the size of files they can write. you certainly want to check the
> client's right to make the file and where, look for file name collisions,
> ownership, etc. there are too many options for etch to get in the middle of
> all that policy fun.
>
> scott out
>
>
> On 4/15/2011 1:22 AM, Prashant Shewale wrote:
>
>> Hi,
>>       Is there built-in object type available in Etch for files (text as
>> well as binary), so that server can transfer file to client or vice-a-versa?
>> I thought of using External Type supported in Etch NSDL and declare language
>> specific file object. But it may cause a problem if I have client and server
>> implementations in different languages. Am I correct?
>>
>> Can you please provide some clues on how to achieve this?
>>
>> Thanks,
>> Prashant
>>
>
>

Re: file transfer over the network

Posted by scott comer <we...@mac.com>.
hi prashant,

there is no builtin support for moving files. but you can easily do that 
yourself.

different api needed perhaps, for text v. binary files.

binary files just go over in chucks as a byte[], about 8k bytes at a 
time would do it. if you were into low-latency transfer of a single 
file, then you can double or triple buffer using async interface.

text file read as string (using java's FileReader or InputStreamReader, 
taking care to select appropriate local CharSet). then transfer as 
chunks of string (eh, 4k or so at a time) (which will be utf-8 encoded 
and then decoded on the other end. at the other end, write the text file 
(using FileWriter or OutputStreamWriter with appropriate CharSet).

we used an api sort of like this:

         RemoteAccountDbServer server = BlahHelper.newServer(...);

         ...

         FileReader r = new FileReader("foobar.txt");

         try {

             String token = server.openFile("foobar.txt", "w");

             try {

                 char[] buf = new char[4096];

                 int n;

                 while ((n = r.read(buf))>  0) {

                     server.writeText(token,new String(buf, 0, n));

                 }

             } finally {

                 server.closeFile(token);

             }

         } finally {

             r.close();

         }


on the back-end you have to use token to locate the corresponding 
FileWriter and take care to clean up abandoned ones, and you have to add 
something that handles the error cases so that partially written files 
are expunged if necessary.

where it matters, you might want to limit the number of file writers and 
/ or the size of files they can write. you certainly want to check the 
client's right to make the file and where, look for file name 
collisions, ownership, etc. there are too many options for etch to get 
in the middle of all that policy fun.

scott out

On 4/15/2011 1:22 AM, Prashant Shewale wrote:
> Hi,
>        Is there built-in object type available in Etch for files (text 
> as well as binary), so that server can transfer file to client or 
> vice-a-versa? I thought of using External Type supported in Etch NSDL 
> and declare language specific file object. But it may cause a problem 
> if I have client and server implementations in different languages. Am 
> I correct?
>
> Can you please provide some clues on how to achieve this?
>
> Thanks,
> Prashant