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. C / C++ / MFC
  4. Transfering files via TCP/IP

Transfering files via TCP/IP

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialcomsysadminhelp
7 Posts 4 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.
  • D Offline
    D Offline
    Dustin Henry
    wrote on last edited by
    #1

    In several of my programs I have been using the CSocketComm class[^] in order to send commands between applications, but what I'm not real clear on is how to transfer files. I'm assuming that I will use a CFile or similar on the client side to read the bytes and transfer to the server, which will re-assemble them into another CFile, but I'm lacking in the specifics such as how many bytes to send at a time etc. Does anyone know of a good tutorial that I can read for some help, or is it as simple as I have stated above. Thanks as always for your help, Dustin

    D M 2 Replies Last reply
    0
    • D Dustin Henry

      In several of my programs I have been using the CSocketComm class[^] in order to send commands between applications, but what I'm not real clear on is how to transfer files. I'm assuming that I will use a CFile or similar on the client side to read the bytes and transfer to the server, which will re-assemble them into another CFile, but I'm lacking in the specifics such as how many bytes to send at a time etc. Does anyone know of a good tutorial that I can read for some help, or is it as simple as I have stated above. Thanks as always for your help, Dustin

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Dustin Henry wrote:

      I'm assuming that I will use a CFile or similar on the client side to read the bytes and transfer to the server...

      I think you'd want to use CFtpConnection.


      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

      "Judge not by the eye but by the heart." - Native American Proverb

      D 1 Reply Last reply
      0
      • D David Crow

        Dustin Henry wrote:

        I'm assuming that I will use a CFile or similar on the client side to read the bytes and transfer to the server...

        I think you'd want to use CFtpConnection.


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        D Offline
        D Offline
        Dustin Henry
        wrote on last edited by
        #3

        I won't actually be connecting to an FTP server, just another computer running my server application implemented with the CSocketComm class. I'm doing this so that I can retrieve current data about the system the application will be hosted on. So in escence I need to send the file from application to application and then have the server side application save the file to disk. Thanks, Dustin

        D 1 Reply Last reply
        0
        • D Dustin Henry

          I won't actually be connecting to an FTP server, just another computer running my server application implemented with the CSocketComm class. I'm doing this so that I can retrieve current data about the system the application will be hosted on. So in escence I need to send the file from application to application and then have the server side application save the file to disk. Thanks, Dustin

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Dustin Henry wrote:

          I won't actually be connecting to an FTP server...

          Understood. Sorry 'bout that. :-O


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          1 Reply Last reply
          0
          • D Dustin Henry

            In several of my programs I have been using the CSocketComm class[^] in order to send commands between applications, but what I'm not real clear on is how to transfer files. I'm assuming that I will use a CFile or similar on the client side to read the bytes and transfer to the server, which will re-assemble them into another CFile, but I'm lacking in the specifics such as how many bytes to send at a time etc. Does anyone know of a good tutorial that I can read for some help, or is it as simple as I have stated above. Thanks as always for your help, Dustin

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            It sounds like you have it. Send any size chunks you want. Keep in mind the default socket internal buffer size is 8K so for best performance keep those flushed (recv data as fast as you can :)). A chunk/packet size right around 500 bytes will insure each chunk fits in one TCP packet but the protocol handles larger chunks. Without increasing the socket buffer sizes, 500 - 8K byte packets will work well.

            D 1 Reply Last reply
            0
            • M Mark Salsbery

              It sounds like you have it. Send any size chunks you want. Keep in mind the default socket internal buffer size is 8K so for best performance keep those flushed (recv data as fast as you can :)). A chunk/packet size right around 500 bytes will insure each chunk fits in one TCP packet but the protocol handles larger chunks. Without increasing the socket buffer sizes, 500 - 8K byte packets will work well.

              D Offline
              D Offline
              Dustin Henry
              wrote on last edited by
              #6

              Great! Thanks as always for the advice Mark!

              M 1 Reply Last reply
              0
              • D Dustin Henry

                Great! Thanks as always for the advice Mark!

                M Offline
                M Offline
                Moak
                wrote on last edited by
                #7

                If you want to achieve high transfer rates you should consider setting you buffer sizes to at least 32K (e.g. read 32K chunks from a file and use a socket send buffer of 32K). Otherwise bulk data transfer will be very likely slower than 100 kB/sec. Tip: Set the server socket send buffer to the wanted size (SO_SNDBUF and possible also SO_REUSEADDR) after you created it, sockets created from the listening socket will then inherit this settings. For further reading see Jon Snader's Effective TCP/IP Programming. /M

                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