UDP

  • unreliable, just add de-multiplexing and error checking on data than IP.
  • Best effort datagram(数据报) service
  • Multiplexing enables sharing of IP datagram service
  • Simple transmitter & receiver
    • Connectionless: no handshaking & no connection state
    • Low header overhead
    • No flow control, no error control, no congestion control
    • UDP datagrams can be lost or out-of-order
  • Applications
    • multimedia (e.g. RTP)
    • network services (e.g. DNS, RIP, SNMP)

UDP Datagram

  • 0-255

    • Well-known ports
  • 256-1023
    • Less well-known ports
  • 1024-65536
    • Ephemeral(短暂的) client ports
  • Source and destination port numbers
    • Client ports are ephemeral(短暂的)
    • Server ports are well-known
    • Max number is 65,535
  • UDP length
    • Total number of bytes in datagram (including header)
    • 8 bytes ≤ length ≤ 65,535
  • UDP Checksum
    • Optionally detects errors in UDP datagram(Because the error packet will be discard)

UDP De-Multiplexing(解复用)

  • All UDP datagrams arriving to IP address B and destination port number n are delivered to the same process
  • Source port number is not used in demultiplexing

UDP Checksum Calculation

  • UDP checksum detects for end-to-end errors
  • Covers pseudoheader(伪报头) followed by UDP datagram
  • IP addresses included to detect against** misdelivery(错误传输)**
  • The use of UDP checksums is optional
  • But hosts are required to have checksums enabled

TCP

  • Reliable byte-stream service
  • More complex transmitter & receiver
    • Connection-oriented: full-duplex(全双工) unicast connection between client & server processes
    • Connection setup, connection state, connection release
    • Higher header overhead
    • Error control, flow control, and congestion(拥塞) control
    • Higher delay than UDP
  • Most applications use TCP
    • HTTP, SMTP, FTP, TELNET, POP3, …

TCP Multiplexing

  • A TCP connection is specified by a 4-tuple(数组)

    • (source IP address, source port, destination IP address, destination port)
  • TCP allows multiplexing of multiple connections between end systems to support multiple applications simultaneously

Reliable Byte-Stream Service

  • Stream Data Transfer:transfers a contiguous stream of bytes across the network, with no indication of boundaries
  • groups bytes into segments(部分)
  • transmits segments as convenient (Push function defined)
    Reliability: error control to deal with IP transfer impairments(损害)

TCP Segment Format

TCP Header

Window Size:TCP protocol need ACK to ensure the packet be transported, if we receive ACK after every packet arriving, it will waste a lot of time.So we need the Window Size to tell us how many packet we can send one time.

  • 16 bits to advertise window size
  • Used for flow control
  • Sender will accept bytes with SN from ACK to ACK + window
  • Maximum win size 65535 bytes
  • TCP Checksum
  • Internet checksum method
  • TCP pseudoheader + TCP segment

UDP and TCP的更多相关文章

  1. 移动端IM系统的协议选型:UDP还是TCP?

    1.前言 对于有过网络编程经验的开发者来说,使用何种数据传输层协议来实现数据的通信,是个非常基础的问题,它涉及到你的第一行代码该如何编写. 从PC时代的IM开始,IM开发者就在为数据传输协议的选型争论 ...

  2. RUDP之一 —— UDP VS TCP

    原文链接 原文:http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/ 介绍 大家好,我是Glenn Fiedler, ...

  3. 第五章 运输层(UDP和TCP三次握手,四次挥手分析)

    序言   通过这章,可以知道其实三次握手和四次挥手其实真的好简单,通过这章的学习,我相信你也会同样的认为,以后在也不需要听到别人问三次握手的过程而自己一脸懵逼了,觉得人家好屌,其实也就是他懂你不懂,仅 ...

  4. 网游中的网络编程系列1:UDP vs. TCP

    原文:UDP vs. TCP,作者是Glenn Fiedler,专注于游戏网络编程相关工作多年. 目录 网游中的网络编程系列1:UDP vs. TCP 网游中的网络编程2:发送和接收数据包 网游中的网 ...

  5. DNS分别在什么情况下使用UDP和TCP

    DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情况下使用这两种协议.     如果用wiresha ...

  6. JAVA基础学习day24--Socket基础一UDP与TCP的基本使用

    一.网络模型 1.1.OIS参考模型 1.2.TCP/IP参考模型 1.3.网络通讯要素 IP地址:IPV4/IPV6 端口号:0-65535,一般0-1024,都被系统占用,mysql:3306,o ...

  7. 初识-----基于Socket的UDP和TCP编程及测试代码

    一.概述 TCP(传输控制协议)和UDP(用户数据报协议是网络体系结构TCP/IP模型中传输层一层中的两个不同的通信协议. TCP:传输控制协议,一种面向连接的协议,给用户进程提供可靠的全双工的字节流 ...

  8. 通信协议之HTTP,UDP,TCP协议

    1.UDP,TCP,HTTP之间的关系 tcp/ip是个协议组,它可以分为4个层次,即网路接口层,网络层,传输层,以及应用层, 在网络层有IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协 ...

  9. Http UDP还是TCP

    http://1024monkeys.wordpress.com/2014/04/01/game-servers-udp-vs-tcp/ 在编写网络游戏的时候,到底使用UDP还是TCP的问题迟早都要面 ...

  10. 游戏服务器:到底使用UDP还是TCP

    http://blog.jobbole.com/64638/ 在编写网络游戏的时候,到底使用UDP还是TCP的问题迟早都要面对. 一般来说你会听到人们这样说:“除非你正在写一个动作类游戏,否则你就用T ...

随机推荐

  1. GIT学习笔记——第一章

    git之vim编辑器退出命令 # 学习笔记 张文军微博主页  张文军码云主页   张文军新浪云主页  张文军博客主页 ## 刚学习git,好多东西没接触过,进入vim后不知道如何出来了,网上找了很多都 ...

  2. 由ArrayList来深入理解Java中的fail-fast机制

    1. fail-fast简介“快速失败”也就是fail-fast,它是Java集合的一种错误检测机制.某个线程在对collection进行迭代时,不允许其他线程对该collection进行结构上的修改 ...

  3. 封装hiredis——C++与redis对接(一)(string的SET与GET操作)

    在菜鸟教程自学了redis,总想着像Mysql一样,在C/C++中进行对接.于是查询了一些资料,最后找到了hiredis.然而直接用它的话,难免有点不方便.于是,对其进行封装. hiredis直接去g ...

  4. Effective C++ .07 virtual析构函数的提供

    主要讲了, 1. virtual析构函数的作用与调用顺序 2. 使用时机,并不是使用了继承就要把基类的析构函数变为虚函数(virtual),只有当用于多态目的时才进行一个virtual析构函数的定义. ...

  5. JavaScript对HTML字符转义与反转义(转码和解码)

    HTML的Encode(转码)和解码(Decode)在平时的开发中也是经常要处理的,在这里总结了使用javascript处理HTML的Encode(转码)和解码(Decode)的常用方式 一.用浏览器 ...

  6. Python-并发编程(进程)

    接下来我们用几天的时间说一说python中并发编程的知识 一.背景知识 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作 ...

  7. console的一些方法

    原文参考http://mp.weixin.qq.com/s?__biz=MzU3MDA0NTMzMA==&mid=2247485510&idx=2&sn=0adff5754a2 ...

  8. 一周一个小demo — vue.js实现备忘录功能

    这个vue实现备忘录的功能demo是K在github上找到的,K觉得这是一个用来对vue.js入门的一个非常简单的demo,所以拿在这里共享一下. (尊重他人劳动成果,从小事做起~  demo原git ...

  9. Python基础-继承与派生

    一.继承 继承是一种创建新的类的方式,在python中,新建的类可以继承自一个或者多个父类,原始类称为基类或超类,新建的类称为派生类或子类. python中类的继承分为:单继承和多继承 class P ...

  10. eclipse svn使用

    简单介绍一些基本操作 1.同步在Eclipse下,右击你要同步的工程->team->与资源库同步->这时会进入同步透视图,会显示出本机与SVN上内容有不同的文件,双击文件名,会显示出 ...