Internet Protocols-1.5 protocol layers, service models

本文探讨了网络协议分层的原因,介绍了TCP/IP模型和ISO/OSI参考模型,阐述了分层如何促进系统维护和透明性。内容涵盖了TCP/IP的各个层次,包括应用层、传输层、网络层、数据链路层和物理层,以及各层的功能和相关设备如路由器、交换机和中继器的作用。
摘要由CSDN通过智能技术生成

1.5 protocol layers, service models

Protocol “layers”

  • hosts
  • routers
  • links of various media
  • applications
  • protocols
  • hardware, software

Layers: each layer implements a service
▪ via its own internal-layer actions
▪ relying on services provided by layer below

分层的结果:每层实现一个服务。服务通过内层的行动来实现,同时依赖着下一层提供的服务。

1.5.1 Why layering?

dealing with complex systems:
▪ explicit structure allows identification, relationship of complex system’s pieces

  • layered reference model for discussion

▪ modularization eases maintenance, updating of system

  • change of implementation of layer’s service transparent to rest of system
  • e.g., change in gate procedure doesn’t affect rest of system

▪ layering considered harmful?

1.5.2 TCP/IP model (internet model)

TCP/IP传输协议,即传输控制/网络协议,它是在网络的使用中的最基本的通信协议。TCP/IP传输协议对互联网中各部分进行通信的标准和方法进行了规定。并且,TCP/IP传输协议是保证网络数据信息及时、完整传输的两个重要的协议。

在使用C++的libhv库实现WebSocketService时,也可以通过设置WebSocketServiceprotocols属性来指定要使用的协议。例如: ```c++ WebSocketService service; service.protocols = {"my-custom-protocol"}; service.onopen = [](WebSocketChannel* channel) { // WebSocket连接建立后的处理逻辑 }; service.onmessage = [](WebSocketChannel* channel, const std::string& msg) { // 接收到WebSocket消息后的处理逻辑 }; service.onclose = [](WebSocketChannel* channel, int code, const std::string& reason) { // WebSocket连接关闭后的处理逻辑 }; ``` 在上面的示例中,WebSocketServiceprotocols属性被设置为"my-custom-protocol"。当客户端发起WebSocket连接时,客户端会在WebSocket握手请求中添加"Sec-WebSocket-Protocol"头,值为"my-custom-protocol"。服务器可以根据该头来确定客户端要使用的协议。 如果需要使用多个协议,则可以在protocols属性中使用逗号分隔的协议列表,例如: ```c++ WebSocketService service; service.protocols = {"my-custom-protocol-1", "my-custom-protocol-2"}; service.onopen = [](WebSocketChannel* channel) { // WebSocket连接建立后的处理逻辑 }; service.onmessage = [](WebSocketChannel* channel, const std::string& msg) { // 接收到WebSocket消息后的处理逻辑 }; service.onclose = [](WebSocketChannel* channel, int code, const std::string& reason) { // WebSocket连接关闭后的处理逻辑 }; ``` 在上面的示例中,WebSocketServiceprotocols属性被设置为"my-custom-protocol-1"和"my-custom-protocol-2"。当客户端发起WebSocket连接时,客户端会在WebSocket握手请求中添加"Sec-WebSocket-Protocol"头,值为"my-custom-protocol-1, my-custom-protocol-2"。服务器可以根据该头来确定客户端要使用的协议。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值