File Transfer Using Remoting
-
I have set up a remoting host and client, and they work well. Now I would like the host to send a file to the client, but can't figure out how to do it. I need a function in the remoted object that would look something like this- Public Function FileTran() as File return C:\test.txt End Function I know this is completely incorrect, but you get the idea of what I'm trying to do. Can anyone please give me some pointers? Thanks in advance, Steve P.S. VB.NET code prefered, but C# would be fine too.
-
I have set up a remoting host and client, and they work well. Now I would like the host to send a file to the client, but can't figure out how to do it. I need a function in the remoted object that would look something like this- Public Function FileTran() as File return C:\test.txt End Function I know this is completely incorrect, but you get the idea of what I'm trying to do. Can anyone please give me some pointers? Thanks in advance, Steve P.S. VB.NET code prefered, but C# would be fine too.
Well, look into Stream objects. I've never used them over a remoting link, but if MS did a really good job it should be seemless. If not, you'll have to chunk and send, which will be slow but will get the job done. Simply chunk your file into a buffer, and send the buffer across the wire as an array of bytes, and then reconsitute. Thats not gonna be a whole lot of fun, though.
-
Well, look into Stream objects. I've never used them over a remoting link, but if MS did a really good job it should be seemless. If not, you'll have to chunk and send, which will be slow but will get the job done. Simply chunk your file into a buffer, and send the buffer across the wire as an array of bytes, and then reconsitute. Thats not gonna be a whole lot of fun, though.
-
Do you think it would matter whether I marshal by ref or serialize? I'm asking because I've never remoted serialized objects, but I've seen them mentioned frequently. :confused:
I've only done minimal work over remoting as well. I figure that serializing a remote object will work great, but again I cant be sure. sorry.
-
I've only done minimal work over remoting as well. I figure that serializing a remote object will work great, but again I cant be sure. sorry.
-
I've been messing around with streams and had all kinds of problems, so I decided to try putting the file into an array of bytes like you said (thanks for that advice). I'm just wondering if you know what the disadvantage of that is.
Large files will be very inefficent, since the whole thing will have to be read into ram, and then 'sent' all at once. Since the wire cant send the data all at once, this will cause a 'lock up' unless you use async or threading.
-
Large files will be very inefficent, since the whole thing will have to be read into ram, and then 'sent' all at once. Since the wire cant send the data all at once, this will cause a 'lock up' unless you use async or threading.
I have tried both methods, returning a file stream vs. filling a big byte[] buffer and I found that the byte[] buffer was much faster which suprised me. I too was worried about the inefficiency of using large chunks of ram but I guess it just depends on the amount of RAM on your server, the average file size and the number of requests served. You could also compress the file data before you put it in the byte[] buffer, saving memory and speeding transfer times. Joel
-
I have tried both methods, returning a file stream vs. filling a big byte[] buffer and I found that the byte[] buffer was much faster which suprised me. I too was worried about the inefficiency of using large chunks of ram but I guess it just depends on the amount of RAM on your server, the average file size and the number of requests served. You could also compress the file data before you put it in the byte[] buffer, saving memory and speeding transfer times. Joel
When you used the buffer method, did you use a singlecall or singleton object? Cause I'm using a singlecall object, and everytime I call the function to send the next buffer, the stream object (that is global in the remoted object) has been erased. On top of that, I can't find a method to have the filestream start at byte X without going back through the file again. Any advice or code snipets you could offer? Thanks for the info, Steve
-
When you used the buffer method, did you use a singlecall or singleton object? Cause I'm using a singlecall object, and everytime I call the function to send the next buffer, the stream object (that is global in the remoted object) has been erased. On top of that, I can't find a method to have the filestream start at byte X without going back through the file again. Any advice or code snipets you could offer? Thanks for the info, Steve
I'm not sure I understand how you are doing the transfer. Basically I tried two methods. The file stream approach works like this. You will have a remote method like GetFile() which returns a file stream object. The client calls GetFile(). The server creates a new file stream object by opening the desired file on the server machine. The server returns this file stream object to the client. The client is then free to call the Read() on the file stream object and when done Close(). Using this method it does not matter what kind of remote object (Singleton etc.) But this method seems to be kind of slow even when you minimize the number of read calls by making your read buffer large. The other method I use is to have a remote method GetFile() that returns a byte[]. The client calls GetFile() and the server opens the desired file reads the entire file into the byte[] and returns this to the client. The client is then able to write the entire byte[] to it's local disk. This seems to work very well for me (tested up to 13MB file). Hope this helps - Joel
-
I'm not sure I understand how you are doing the transfer. Basically I tried two methods. The file stream approach works like this. You will have a remote method like GetFile() which returns a file stream object. The client calls GetFile(). The server creates a new file stream object by opening the desired file on the server machine. The server returns this file stream object to the client. The client is then free to call the Read() on the file stream object and when done Close(). Using this method it does not matter what kind of remote object (Singleton etc.) But this method seems to be kind of slow even when you minimize the number of read calls by making your read buffer large. The other method I use is to have a remote method GetFile() that returns a byte[]. The client calls GetFile() and the server opens the desired file reads the entire file into the byte[] and returns this to the client. The client is then able to write the entire byte[] to it's local disk. This seems to work very well for me (tested up to 13MB file). Hope this helps - Joel
That makes sense. I was trying to send only 4k at a time, so I was having all sorts of problems with getting the server to send the next 4k rather than the first 4k. But I realize that I'm never actually going to be sending a file too big to fit into a byte array. I'll just send it in one big array like you did. Thanks for the help, Steve :)