Learn how to a build a cloud-first strategyRegister Now


udp file transfer

Posted on 2006-04-22
Medium Priority
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
  • 2
LVL 45

Accepted Solution

sunnycoder earned 500 total points
ID: 16517413
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.


Assisted Solution

Dragon_Krome earned 500 total points
ID: 16560089
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

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

810 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