TCP Headers and UDP Headers Explained

Lifewire 

Updated July 22, 2019
272

Transmission Control Protocol and User Datagram Protocol are the two standard transport layers used with Internet Protocol.

 

Both TCP and UDP use headers as part of packaging message data for transfer over network connections. TCP headers and UDP headers each contain a set of parameters called fields defined by the protocol technical specifications.

 

TCP Header Format

Each TCP header has ten required fields totaling 20 bytes (160 bits) in size. They can also optionally include an additional data section up to 40 bytes in size.

 

It takes 8 bits to equal 1 byte.

TCP headers appear in the following sequence:

 
  1. Source TCP port number (2 bytes or 16 bits)

     
  2. Destination TCP port number (2 bytes or 16 bits)

     
  3. Sequence number (4 bytes or 32 bits)

     
  4. Acknowledgment number (4 bytes or 32 bits)

     
  5. TCP data offset (4 bits)

     
  6. Reserved data (3 bits)

     
  7. Control flags (up to 9 bits)

     
  8. Window size (2 bytes or 16 bits)

     
  9. TCP checksum (2 bytes or 16 bits)

     
  10. Urgent pointer (2 bytes or 16 bits)

     
  11. TCP optional data (0-40 bytes)

     

The headers supply specific information:

 
  • Source and destination TCP port numbers are the communication endpoints for sending and receiving devices.
  • Message senders use sequence numbers to mark the ordering of a group of messages. Both senders and receivers use the acknowledgment numbers field to communicate the sequence numbers of messages that are either recently received or expected to be sent.
  • The data offset field stores the total size of a TCP header in multiples of four bytes. A header not using the optional TCP field has a data offset of 5 (representing 20 bytes), while a header using the maximum-sized optional field has a data offset of 15 (representing 60 bytes).
  • Reserved data in TCP headers always has a value of zero. This field serves the purpose of aligning the total header size as a multiple of four bytes (important for the efficiency of computer data processing).
  • TCP uses a set of six standard and three extended control flags (each an individual bit representing on or off) to manage data flow in specific situations. One bit flag, for example, initiates TCP connection reset logic.
 
  • TCP senders use a number called window size to regulate how much data they send to a receiver before requiring an acknowledgment in return. If the window size becomes too small, network data transfer will be unnecessarily slow, while if the window size becomes too large, the network link can become saturated (unusable for any other applications) or the receiver may not be able to process incoming data quickly enough (also resulting in slow performance). Windowing algorithms built into the protocol dynamically calculate size values and
  • use this field of TCP headers to coordinate changes between senders and receivers.
  • The checksum value inside a TCP header is generated by the protocol sender as a mathematical technique to help the receiver detect messages that are corrupted or tampered with.
  • The urgent pointer field is often set to zero and ignored, but in conjunction with one of the control flags, it can be used as a data offset to mark a subset of a message as requiring priority processing.
 
  • Usages of optional TCP data include support for special acknowledgment and window scaling algorithms.
 

UDP Header Format

Because UDP is significantly more limited in capability than TCP, its headers are much smaller. A UDP header contains 8 bytes, divided into the following four required fields:

 
  • Source port number (2 bytes)
  • Destination port number (2 bytes)
  • Length of data (2 bytes)
  • UDP checksum (2 bytes)
 

UDP inserts header fields into its message stream in the order listed above.

 
  1. Source and destination UDP port numbers are the communication endpoints for sending and receiving devices.

     
  2. The length field in UDP represents the total size of each datagram including both header and data. This field ranges in value from a minimum of 8 bytes (the required header size) to sizes above 65,000 bytes.

     
  3. Similar to TCP, a UDP checksum allows receivers to cross-check incoming data for any corrupted bits of the message.

     

转载于:https://my.oschina.net/u/1777508/blog/3100887

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值