Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java socket udp TCP/IP
heyy guys..
 
m implementing PEER TO PEER FILE TRANSFER..
 
What protocol should I use? TCP or UDP? And why?
Posted 5-Jan-12 20:00pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Dear Abhishek ,
 
Transmission Control Protocol is a connection-oriented protocol, which means that it requires handshaking to set up end-to-end communications. Once a connection is set up user data may be sent bi-directionally over the connection.
 
So if the network is VPN,Lan or Intranet, personally I will prefer TCP.
 
UDP is a simpler message-based connectionless protocol. Connectionless protocols do not set up a dedicated end-to-end connection. Communication is achieved by transmitting information in one direction from source to destination without verifying the readiness or state of the receiver. However, one primary benefit of UDP over TCP is the application to voice over internet protocol (VoIP) where any handshaking would hinder clear voice communication. It is assumed in VoIP UDP that the end users provide any necessary real time confirmation that the message has been received.
 
Comparisons of TCP and UDP
 
TCP
Reliable: TCP manages message acknowledgment, retransmission and timeout. Multiple attempts to deliver the message are made. If it gets lost along the way, the server will re-request the lost part. In TCP, there's either no missing data, or, in case of multiple timeouts, the connection is dropped.
Ordered: if two messages are sent over a connection in sequence, the first message will reach the receiving application first. When data segments arrive in the wrong order, TCP buffers the out-of-order data until all data can be properly re-ordered and delivered to the application.
Heavyweight: TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control.
Streaming: Data is read as a byte stream, no distinguishing indications are transmitted to signal message (segment) boundaries.
 
UDP
Unreliable: When a message is sent, it cannot be known if it will reach its destination; it could get lost along the way. There is no concept of acknowledgment, retransmission or timeout.
Not ordered: If two messages are sent to the same recipient, the order in which they arrive cannot be predicted.
Lightweight: There is no ordering of messages, no tracking connections, etc. It is a small transport layer designed on top of IP.
Datagrams: Packets are sent individually and are checked for integrity only if they arrive. Packets have definite boundaries which are honored upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent.
No congestion control: UDP itself does not avoid congestion, and it's possible for high bandwidth applications to trigger congestion collapse, unless they implement congestion control measures at the application level.
 
If you are think about security levels and reliable data transfer also
check these links, why Udp
 
A UDP-based Reliable Data Transfer Library[^]
 
http://zgp.org/pipermail/p2p-hackers/2004-December/002221.html[^]
 

 
This will helpful to you
 

 
Thanks & Regards
  Permalink  
v8
Comments
RaisKazi at 6-Jan-12 1:59am
   
My 5.
Sridhar Patnayak at 6-Jan-12 2:02am
   
Thanks RaisKazi
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Yes, agreed. But what i want is precisely how easy or difficult is it to implement either of the options.
 
Also, if you have an experience of making an application of similar kind, i can get a better answer.
  Permalink  
v2
Comments
Sridhar Patnayak at 6-Jan-12 1:44am
   
My self I am experienced with tcp and VPN, and I felt that it is much easier to implement in the suggested networks like Lan and VPN. Their are several articles which will give you information to implement tcp file transfer. And now check my modified solution, when udp is need to implement. link provided (A UDP-based Reliable Data Transfer Library).
Mehdi Gholam at 6-Jan-12 2:01am
   
Use the comments, do not post solutions for further assistance.
Abhishek Nandgaonkar at 6-Jan-12 2:04am
   
yeah sorry.. new to this site.. dint know that..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 295
1 Maciej Los 280
2 Afzaal Ahmad Zeeshan 224
3 BillWoodruff 205
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 6 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100