Re: Distributed Objects, NSFileHandle and file transfer
Re: Distributed Objects, NSFileHandle and file transfer
- Subject: Re: Distributed Objects, NSFileHandle and file transfer
- From: Ken Thomases <email@hidden>
- Date: Wed, 6 Aug 2008 05:41:08 -0500
On Aug 6, 2008, at 4:07 AM, Gert Andreas wrote:
Using NSData and sending a file at once doesn't work as you need to
allocate too much memory for large files.
So i made an attempt using distributed objects and vending the
NSFileHandle from to file on the client side to the server.
- (void)sendFileHandle:(in byref NSFileHandle *)fileHandle;
and the read the file till the end using:
dataToWrite = [fileHandle readDataOfLength:100000];
That works indeed great but i'm wondering if it's a good idea using
DOs for transferring files?
You haven't transferred the file (or even the file handle) to the
server. What you've done is create a proxy in the server for the file
handle object in the client. Then, the readDataOfLength: message is
sent to the proxy which forwards it to the client and then a proxy of
the resulting data object is returned to the server. This is perhaps
the worst of all worlds because then all operations on the data object
proxy will cause further D.O. communication. If readDataOfLength: were
declared in a protocol to return its result bycopy, then at least
you'd transfer an actual copy of the data object to the server, where
it could be used locally without further D.O. overhead, but that
wouldn't be any better than just sending the data in the first place.
NSFileHandle doesn't adopt the NSCoding protocol and so can't be sent
by-copy to the server.
If the client and server are on the same computer, you have a couple
of approaches:
If you really want the server to obtain an open file from the client,
you may have to use Unix-domain sockets. See "man unix". There's no
Cocoa front-end to this, as far as I know. Unix domain sockets allow
you to transfer a file descriptor from one process to another on the
same computer. You can use NSFileHandle to obtain the file descriptor
in the client, and you can create an NSFileHandle from the file
descriptor once its been transmitted to the server.
(Hmm. Come to think of it, you may be able to use NSSocketPort and
NSPortMessage to transmit a file descriptor between processes over a
Unix-domain socket.)
Another approach would be to transfer the file path to the server, but
then the file needs to be accessible by the server, which may have
different access privileges than the client.
If the client and server are on different computers, then you can't
really avoid the need to transmit the data in the file. In that case,
you might want to use NSStream or, if that's not flexible enough, a
TCP socket you open yourself wrapped in an NSFileHandle.
Cheers,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden