udp file transfer

Posted on 2006-04-22
Last Modified: 2006-11-18

I am fairly new to this but I have managed to get a basic message passing client - server program working fine but I would now like to make it pass a file from client to the server.

I was wondering if any of you could give me some guideance on the structre and functions i need.

Question by:devonflyers
    LVL 45

    Accepted Solution

    Hi devonflyers,

    > I would now like to make it pass a file from client to the server.
    Sounds like homework assignment so I am not giving you the code, only the guidelines ...

    Code is essentially the same. In your current program, you would be packing your buffer and executing a send()/sendto().
    The only difference now will be that you wil have to do this in a loop ... something like

    open file
    while (there is input to read)
            read next BUFFERSIZE bytes into buffer
            send (buffer)
    end loop
    close file

    There are a couple of issues
    1. How would receiver know that file transfer is complete?
    You can either send the length of data in first packet that you send or you can use some sentinnel sequence of characters to indicate end of transfer

    2. You sre using UDP which is by very nature unreliable. If one of the packets gets lost, receiver would never be able to reconstruct the file. Also, depending on the packet that gets lost, it may not be able to detect end of transfer or beginning of file transfer. Consider shifting to TCP if your problem definition permits that.

    LVL 5

    Assisted Solution

    if you want to use udp for transfer, you must think that the packets might arrive out of order too, as udp doesn't guarantee the order of the packets, so you might want to create a special header inside your packet containing a sequence number (to know what number this packet has - this way you'll also know if you've lost some packets) and perhaps some flags, if you'd like to implement a protocol (e.g. flags for requesting retransmission of a lost packet).
    LVL 45

    Expert Comment

    If you are going to take so much pain, why not use time tested TCP instead :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now