cip协议服务器,CIP 传输协议

c4468b3f4df77e96b0a416fa2a870fba.png

CIP 传输协议

摘要

本文主要说明用于传输CIP请求/响应,索引对象,实现它们在TCP,邮件和HTTP上传输的三个协议。相关的资料请在其它资料中查询。

1. 协议

本节说明用于传输CIP索引对象和维护网结构。本文主要定义定义消息格式,传输机制。CIP协议的设计思想是一种块设计思想。它不依赖于许多于协议定义工具,或文本编码方式,而是利用现有的协议技术进行设计。这样可以使设计和实现简化。这也是利用现有的Internet技术实现应用层服务的方法。

2 MIME消息交换机制

CIP的消息交互是通过交换MIME消息进行的。消息在双向可靠传输的基础上进行。本文利用TCP,HTTP和邮件传输进行消息传输。CIP服务器开始连接,它称为发送CIP,而响应发送CIP的服务器称为接收CIP。

2.1 流传输

CIP在双向TCP连接上通过简单文本协议传输,它的操作可以在任何TCP端口上进行,因此配置信息也包括了主机名和端口号。发送CIP的动作由接收CIP的响应码加以确定。这些码的格式见下文。为了进行向后兼容Whois 服务器, CIPv3发送CIP必须首先确定支持新协议。通过发送下面非法的Whois 系统命令完成上述功能:"# CIP-Version: 3"。在现在的Whois 服务器上,如果实现了CIP版本1或2,就会导致500系列的响应,服务器中断连接,如果服务器实现了CIPv3,它会响应300。这个300中的3代表版本3,以后的版本也可以利用这种方法。下面是一个交换的例子:

注意:如果发送CIP能够确定服务器实现了CIPv3,它可以发送"# CIP-Version: 3"串,然后跟一个CIPv3请求,这个优化在已知的同构CIP网结构中是有用的,这样可以避免等待。

一旦发送CIP确定服务器支持CIPv3请求,它可以以MIME格式发送请求,每个请求以""结束。

Cip-Req = Req-Hdrs CRLF Req-Body

Req-Hdrs = *( Version-Hdr | Req-Cntnt-Hdr )

Req-Body = Body ; format of request body as in [CIP-MIME]

Body = Data CRLF "." CRLF

Data = ; data with CRLF "." CRLF replaced by CRLF ".." CRLF

Version-Hdr = "Mime-Version:" "1.0" CRLF

Req-Cntnt-Hdr = "Content-Type:" Req-Content CRLF

Req-Content = ; format is specified in [CIP-MIME]

Cip-Rsp = Rsp-Code CRLF [ Rsp-Hdrs CRLF Rsp-Body ] [ Indx-Cntnt-Hdr CRLF Index-Body ]

Rsp-Code = DIGIT DIGIT DIGIT Comment

Comment = ; any chars except CR and LF

Rsp-Hdrs = *( Version-Hdr | Rsp-Cntnt-Hdr )

Rsp-Cntnt-Hdr = "Content-Type:" Rsp-Content CRLF

Rsp-Content = ; format is specified in [CIP-MIME]

Rsp-Body = Body ; format of response body as in [CIP-MIME]

Indx-Cntnt-Hdr = "Content-Type:" Indx-Obj-Type CRLF

Indx-Obj-Type = ; any registered index object's MIME-type the format is specified in [RFC2045]

Index-Body = Body ; format defined in each index specifications

CRLF = CR LF ; Internet standard newline

CR = %x0D ; carriage return

LF = %x0A ; linefeed

DIGIT = %x30-39

消息以SMTP形式结束,数据以字节传输,除了看到1*["."],这种情况下要加一个句号。在数据传输结束时以"."表示。接收方要将结束标记略过。接收方的响应分为200,400和500系列。响应也以SMTP形式的消息界定。在返回响应后,接收CIP必须准备接收下一个请求,将状态返回到发送CIP刚刚确定版本时的状态。如果发送CIP不再发请求,则可以关闭连接。作为响应,接收CIP必须广放弃读入消息,并准备新的发送CIP连接。下面是一个例子,这里的行结束显式给出。中间的空间只为可读性而设置,注释在大括号内。

{ 发送CIP连接到接收CIP }

<<< % 220 Example CIP server ready

>>> # CIP-Version: 3

<<< % 300 CIPv3 OK!

>>> Mime-Version: 1.0

>>> Content-type: application/index.cmd.datachanged; type=

>>> x-tagged-index-1; dsi=1.2.752.17.5.10

>>>

>>> updatetype: incremental tagbased

>>> thisupdate: 855938804

>>> lastupdate: 855940000

>>> .

<<< % 200 Good MIME message received

>>> MIME-Version: 1.0

>>> Content-Type: application/index.obj.tagged;

>>> dsi=1.2.752.17.5.10;

>>> base-uri="ldap://ldap.umu.se/dc=umu,dc=se"

>>>

>>> version: x-tagged-index-1

>>> updatetype: incremental

>>> lastupdate: 855940000

>>> thisupdate: 855938804

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com

特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Contents 3-1 Introduction........................................................................................................................................................ 3 3-2 Scope.................................................................................................................................................................. 3 3-3 CIP packets over TCP/IP ................................................................................................................................... 3 3-3.1 Unconnected messages .............................................................................................................................. 3 3-3.2 CIP transport class 0 and class 1 connections ............................................................................................ 5 3-3.2.1 CIP transport class 0 and class 1 packets ............................................................................................... 5 3-3.2.2 Behavior of class 0 and class 1 connections (informative) .................................................................... 5 3-3.3 CIP Transport class 2 and class 3 connections ........................................................................................... 6 3-3.4 CIP Transport classes 4 through 6 ............................................................................................................. 6 3-4 Connection Manager object ............................................................................................................................... 6 3-4.1 Connection parameters............................................................................................................................... 6 3-4.2 Connection type ......................................................................................................................................... 7 3-4.3 Priority ....................................................................................................................................................... 7 3-4.4 Trigger Type .............................................................................................................................................. 7 3-4.5 Connection size .......................................................................................................................................... 7 3-4.6 Connection request time-out ...................................................................................................................... 7 3-4.7 Connection path ......................................................................................................................................... 7 3-4.7.1 Network connection ID .......................................................................................................................... 8 3-4.8 Forward_open for CIP transport class 2 and class 3 connections ............................................................ 11 3-4.9 Forward_open for CIP transport class 0 and class 1 connections ............................................................ 11 3-4.9.1 General ................................................................................................................................................. 11 3-4.9.2 Mapping connections to IP multicast addresses ................................................................................... 11 3-4.9.3 Completing the multicast connection (informative) ............................................................................. 12 3-5 CIP transport class 0 and class 1 connected data ............................................................................................. 12 3-5.1 UDP datagrams ........................................................................................................................................ 12 3-5.2 CIP transport class 0 and class 1 packet ordering .................................................................................... 12 3-5.3 Screening incoming connected data ......................................................................................................... 13 3-6 IP multicast scoping and address allocation..................................................................................................... 13 3-6.1 Background (informative) ........................................................................................................................ 13 3-6.1.1 General ................................................................................................................................................. 13 3-6.1.2 Current scoping practices ..................................................................................................................... 14 3-6.1.3 Current address allocation practices..................................................................................................... 14 3-6.1.4 Evolving Internet standards.................................................................................................................. 14 3-6.2 Interim scoping strategy ........................................................................................................................... 15 3-6.3 Interim allocation strategy........................................................................................................................ 15
UDP协议在客户端和服务器之间进行视频传输的C源码如下: 客户端端代码: ``` #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <arpa/inet.h> #define BUFFER_SIZE 1024 #define SERVER_IP "127.0.0.1" #define SERVER_PORT 5000 int main() { int sockfd; struct sockaddr_in server_addr; socklen_t addr_len = sizeof(server_addr); char buffer[BUFFER_SIZE]; FILE *fp; // 创建UDP套接字 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("Socket creation failed"); exit(EXIT_FAILURE); } memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(SERVER_PORT); if (inet_pton(AF_INET, SERVER_IP, &(server_addr.sin_addr)) <= 0) { perror("Invalid address/ Address not supported"); exit(EXIT_FAILURE); } if ((fp = fopen("video.mp4", "rb")) == NULL) { perror("Failed to open file"); exit(EXIT_FAILURE); } while (1) { // 读取文件内容到缓冲区 int n = fread(buffer, 1, sizeof(buffer), fp); if (n <= 0) { break; } // 发送缓冲区内容到服务器 sendto(sockfd, buffer, n, 0, (struct sockaddr*)&server_addr, addr_len); } printf("File sent successfully.\n"); fclose(fp); close(sockfd); return 0; } ``` 服务器端代码: ``` #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <arpa/inet.h> #define BUFFER_SIZE 1024 #define SERVER_PORT 5000 int main() { int sockfd; struct sockaddr_in server_addr, client_addr; socklen_t addr_len = sizeof(client_addr); char buffer[BUFFER_SIZE]; FILE *fp; // 创建UDP套接字 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("Socket creation failed"); exit(EXIT_FAILURE); } memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); server_addr.sin_port = htons(SERVER_PORT); // 将套接字与服务器地址绑定 if (bind(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) { perror("Bind failed"); exit(EXIT_FAILURE); } if ((fp = fopen("received_video.mp4", "wb")) == NULL) { perror("Failed to open file"); exit(EXIT_FAILURE); } while (1) { // 接收客户端发送的数据 int n = recvfrom(sockfd, buffer, BUFFER_SIZE, 0, (struct sockaddr*)&client_addr, &addr_len); if (n <= 0) { break; } // 将接收到的数据写入文件 fwrite(buffer, 1, n, fp); } printf("File received successfully.\n"); fclose(fp); close(sockfd); return 0; } ``` 以上是通过UDP协议进行视频传输的基本C源码,其中客户端从本地读取视频文件,将数据逐块发送给服务器端,服务器端接收到数据后将其写入新的文件中。需要注意的是,客户端和服务器端需要使用相同的IP地址和端口号,并且确保服务器端已启动并监听指定端口。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值