• C

udp file transfer


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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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).
If you are going to take so much pain, why not use time tested TCP instead :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.