这些网络概念你都了解吗?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010924834/article/details/76724267

通信协议

Communication Protocol

In telecommunications, a communication protocol is a system of rules that allow two or more entities of a communications system to transmit information via any kind of variation of a physical quantity. The protocol defines the rules syntax, semantics and synchronization of communication and possible error recovery methods. Protocols may be implemented by hardware, software, or a combination of both.

通信协议:网络中的设备之间进行通信的规则约束
通信协议的三要素
syntax(语法)——How——包括数据的格式、编码和信号等级(电平的高低)等
semantics(语义)——What——通信内容,包括数据内容、含义以及控制信息
synchronization of communication(通信时序)——When——即何时通信,明确通信的顺序、速率匹配和排序

TCP/IP or OSI

To implement a networking protocol, the protocol software modules are interfaced with a framework implemented on the machine’s operating system. This framework implements the networking functionality of the operating system. The best known frameworks are the TCP/IP model and the OSI model.

通过上面的描述我们可以得知TCP/IP模型和OSI模型都是通信协议的框架。该框架将协议进行模块化划分。

OSI

The Open Systems Interconnection model (OSI model) is a conceptual model that characterizes and standardizes the communication functions of a telecommunication or computing system without regard to their underlying internal structure and technology. Its goal is the interoperability of diverse communication systems with standard protocols. The model partitions a communication system into abstraction layers. The original version of the model defined seven layers.

OSI是一个概念模型不涉及内部实现的技术。目的是通过标准的协议来实现不同通信系统之间的互操作性。

这里写图片描述

TCP/IP

The Internet protocol suite is the conceptual model and set of communications protocols used on the Internet and similar computer networks. It is commonly known as TCP/IP because the original protocols in the suite are the Transmission Control Protocol (TCP) and the Internet Protocol (IP). It is occasionally known as the Department of Defense (DoD) model, because the development of the networking model was funded by DARPA, an agency of the United States Department of Defense.

这里写图片描述

通信方式

通信方式 特点
单工 消息发送方和接收方固定,只存在单方向信号流
半双工 消息发送方和接受方可以互换,但同一时刻只能存在单方向信号流
全双工 消息两端既是发送方又是接收方,同一时刻存在两种方向信号流

网络编程IO模型

IO请求的两个阶段:

等待资源阶段(等待数据到达):IO请求一般需要请求特殊的资源(如磁盘、RAM、文件),当资源被上一个使用者使用没有被释放时,IO请求就会被阻塞,直到能够使用这个资源。

使用资源阶段(拷贝数据):真正进行数据接收和发生。

举例说就是排队和服务。

在等待数据阶段,IO分为阻塞IO和非阻塞IO。

阻塞IO:资源不可用时,IO请求一直阻塞,直到反馈结果(有数据或超时)。

非阻塞IO:资源不可用时,IO请求离开返回,返回数据标识资源不可用

在使用资源阶段,IO分为同步IO和异步IO。

同步IO:应用阻塞在发送或接收数据的状态,直到数据成功传输或返回失败。

异步IO:应用发送或接收数据后立刻返回,数据写入OS缓存,由OS完成数据发送或接收,并返回成功或失败的信息给应用。

按照Unix的5个IO模型划分:

  1. 阻塞IO
  2. 非阻塞IO
  3. IO复用
  4. 信号驱动的IO
  5. 异步IO

前4种都是同步IO。

这里写图片描述

HTTP长连接 短连接

HTTP长连接和短连接其实是TCP的长连接和短连接

如何区分?

短连接:在HTTP/1.0中,默认使用的是短连接。也就是说,浏览器和服务器每进行一次HTTP操作,就建立一次连接,但任务结束就中断连接。如果客户端浏览器访问的某个HTML或其他类型的 Web页中包含有其他的Web资源,如JavaScript文件、图像文件、CSS文件等;当浏览器每遇到这样一个Web资源,就会建立一个HTTP会话。
长连接:但从 HTTP/1.1起,默认使用长连接,用以保持连接特性。使用长连接的HTTP协议,会在响应头有加入这行代码:

Connection:keep-alive 

在使用长连接的情况下,当一个网页打开完成后,客户端和服务器之间用于传输HTTP数据的 TCP连接不会关闭,如果客户端再次访问这个服务器上的网页,会继续使用这一条已经建立的连接。Keep-Alive不会永久保持连接,它有一个保持时间,可以在不同的服务器软件(如Apache)中设定这个时间。实现长连接要客户端和服务端都支持长连接。

HTTP协议的长连接和短连接,实质上是TCP协议的长连接和短连接。

总结

通信协议是网络中设备之间进行通信的一组规则。
OSI模型和TCP/IP模型是对通信协议进行模块化划分后的标准框架。
OI模型根据等待数据到达阶段和数据拷贝阶段,请求时否阻塞而分为5种。
短连接代表一次HTTP请求之后连接就断开了;长连接则还保持连接,但是有一个保持时间。

参考文章

https://en.m.wikipedia.org/wiki/Communications_protocol
http://pengjiaheng.iteye.com/blog/847615
http://blog.jobbole.com/93960/

猜你喜欢

转载自blog.csdn.net/u010924834/article/details/76724267