TCP与UDP区别
TCP---传输控制协议,提供的是面向连接、可靠的字节流服务。当客户和服务器彼此交换数据前,必须先在双方之间建立一个TCP连接,之后才能传输数据。TCP提供超时重发,丢弃重复数据,检验数据,流量控制等功能,保证数据能从一端传到另一端。
UDP---用户数据报协议,是一个简单的面向数据报的运输层协议。UDP不提供可靠性,它只是把应用程序传给IP层的数据报发送出去,但是并不能保证它们能到达目的地。由于UDP在传输数据报前不用在客户和服务器之间建立一个连接,且没有超时重发等机制,故而传输速度很快
Overview
TCP (Transmission Control Protocol) is the most commonly usedprotocol on the Internet. The reason for this is because TCP offerserror correction. When the TCP protocol is used there is a"guaranteed delivery." This is due largely in part to a methodcalled "flow control." Flow control determines when data needs tobe re-sent, and stops the flow of data until previous packets aresuccessfully transferred. This works because if a packet of data issent, a collision may occur. When this happens, the clientre-requests the packet from the server until the whole packet iscomplete and is identical to its original.
UDP (User Datagram Protocol) is anther commonly used protocol onthe Internet. However, UDP is never used to send important datasuch as webpages, database information, etc; UDP is commonly usedfor streaming audio and video. Streaming media such as WindowsMedia audio files (.WMA) , Real Player (.RM), and others use UDPbecause it offers speed! The reason UDP is faster than TCP isbecause there is no form of flow control or error correction. Thedata sent over the Internet is affected by collisions, and errorswill be present. Remember that UDP is onlyconcerned with speed. This is the main reason why streaming mediais not high quality.
On the contrary, UDP has been implemented among some * horseviruses. Hackers develop scripts and *s to run over UDP inorder to mask their activities. UDP packets are also used in DoS(Denial of Service) attacks. It is important to know the differencebetween TCP port 80 and UDP port 80. If you don't know what portsare go here.
Frame Structure
As data moves along a network, various attributes are added tothe file to create aframe. This process is calledencapsulation. There are different methods ofencapsulation depending on which protocol andtopology are being used. As a result, theframe structure of these packets differ as well. The images belowshow both the TCP and UDP frame structures.
TCP FRAME STRUCTURE
UDP FRAME STRUCTURE
The payload field contains the actually data. Notice thatTCP has a more complex frame structure. This is largely due to thefact the TCP is a connection-oriented protocol. The extra fieldsare need to ensure the "guaranteed delivery" offered by TCP.
UDP
TCP
TCP与UDP的选择