-2

I'm sending/receiving a file (on localhost) through UDP Datagram, and now I want to assemble the received packets to create that received file and save it on some path (desktop for example) .. what should I do? any idea?

You can find my client/server implementation here:

Is it possible to use just 1 UDPSocket for sending/receiving on the same port?

Thanks!

Community
  • 1
  • 1
ZelelB
  • 1,546
  • 5
  • 31
  • 60
  • Since datagram packets can arrive out of order (or not at all), you have to include information about where a particular packet lives in the file, and some retry mechanism. But to be honest, if you don't realize this already, you probably shouldn't be using datagram packets for file transfer. In fact, even if you do realize it, you shouldn't be using datagram packets for file transfer. – kdgregory Dec 29 '12 at 23:33
  • thanks for your answer! but I know already, and it's a homework.. but I'm adding an artificial header to the packet, and I put on it a checksum, length and sequence-number for each packet sent.. so it's kinda "reliable".. you can see the code (link above) So could you help me further whith my question? – ZelelB Dec 30 '12 at 16:21
  • You already have a header and you don't know how to add another value to that header? I fail to see what the problem is here other than a lack of thinking through the problem. – kdgregory Jan 01 '13 at 12:53

1 Answers1

0

You have to do is: algorithms like TCP. Create protocol over UDP like TCP Protocol.

1) You need sequencing UDP packets 2) You don't need custom checksum as UDP is already having 3) Sender side buffers, your code will write to buffers and your protocol will send data from buffers to receiver as some length packets (MTU size is good, around 1400 bytes in UDP packet). Packets will have sequence numbers. 4) Receiver on receiving packets checks for seq. number, if received packets' seq. no is expected seq no, you can buffer it for writing in file, else put this packet in temporary buffer and send back sender the information of lost packets. 5) Receiver will send back ACKs of highest received seq no or lost seq nos. 6) Sender side will perform according to replies from receiver.

I think you have got some idea. You need multithreading.. on each machine you need some sender, receiver, application threads for implementing algorithms like this.

BTW, I have implemented this algorithm, and got great result. I am able to transfer file with 75 Mbps speed where TCP was failing to peak speed above 5 Mbps on 100 Mbps internet connection with around 100-200 ms roundtrip time. From India to Canada.

I hope this helped you.

nullptr
  • 3,160
  • 4
  • 31
  • 66