954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Peer to Peer File Transfer application, TCP or UDP to use?

heyy guys..

m implementing PEER TO PEER FILE TRANSFER..

What protocol should I use? TCP or UDP? And why?

abhishek_s_n
Newbie Poster
6 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

TCP.
UDP messages are sent, but there is no check or guarantee whether they arrive or not. Also if you send multiple UDP packets there's no guarantee that they will arrive in the same order as they were sent.

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

heyy guys..

m implementing PEER TO PEER FILE TRANSFER..

What protocol should I use? TCP or UDP? And why?


JamesCherrill answered that and here's an example of a TCP: http://systembash.com/content/a-simple-java-tcp-server-and-tcp-client/ and UDP: http://systembash.com/content/a-simple-java-udp-server-and-udp-client/ so you can see it for yourself

DavidKroukamp
Practically a Master Poster
Team Colleague
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
 

Its important to understand how sending information over a connection works before deciding on a protocol. When you send data over a connection it is broken down into small, standard size chunks called packets. The difference in the two protocols you've described is how they handle packets.

UDP simply takes a file, breaks it up, and sends each packet out onto the network. This sounds good in theory, but problems in the network can easily cause some packets to be lost or arrive in a different order than they were sent (think of it like the mail).

TCP also breaks up a file, but it adds a little bit of information that tells the receiving client where it goes when the file gets put back together. This fixes the out of order problem. TCP also requires a client to tell the sender when it receives a packet, which means any lost packets will be resent (and so on until it reaches the client).

I would strongly recommend TCP for the application you are describing. My team used TCP for a similar system we made as a school project.

dmanw100
Posting Whiz in Training
242 posts since Apr 2008
Reputation Points: 104
Solved Threads: 27
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: