Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. File Transfer Using Remoting

File Transfer Using Remoting

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharptutorialquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SHaroz
    wrote on last edited by
    #1

    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.

    C 1 Reply Last reply
    0
    • S SHaroz

      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.

      C Offline
      C Offline
      Christopher Lord
      wrote on last edited by
      #2

      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.

      S 1 Reply Last reply
      0
      • C Christopher Lord

        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.

        S Offline
        S Offline
        SHaroz
        wrote on last edited by
        #3

        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:

        C 1 Reply Last reply
        0
        • S SHaroz

          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:

          C Offline
          C Offline
          Christopher Lord
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • C Christopher Lord

            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.

            S Offline
            S Offline
            SHaroz
            wrote on last edited by
            #5

            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.

            C 1 Reply Last reply
            0
            • S SHaroz

              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.

              C Offline
              C Offline
              Christopher Lord
              wrote on last edited by
              #6

              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.

              L 1 Reply Last reply
              0
              • C Christopher Lord

                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.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                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

                S 1 Reply Last reply
                0
                • L Lost User

                  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

                  S Offline
                  S Offline
                  SHaroz
                  wrote on last edited by
                  #8

                  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

                  L 1 Reply Last reply
                  0
                  • S SHaroz

                    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

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    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

                    S 1 Reply Last reply
                    0
                    • L Lost User

                      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

                      S Offline
                      S Offline
                      SHaroz
                      wrote on last edited by
                      #10

                      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 :)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups