webserver中webpush技术的最简单cgi示例
嵌入式中一般是使用开源的Goahead webserver服务器,CGI也都是用C语言进行编写开发的。项目中想要在web上实现图片流的视频播放效果,考虑到两种方法,一种是浏览器端来进行图片的主动获取,一种是服务器端来进行图片的主动推送,即webpush技术。webpush技术显然更高效,但在Goahead上的实现过程中遇到了点问题。 下面是一个最简单的使用C语言编写的CGI来测试使用Goahead是否支持Webpush技术,以及运行的机制。 #include <stdio.h> #include <stdlib.h> int main() { int ret,i; printf("HTTP/1.1 200\r\n"); //http协议的头及push技术头 printf("Content-type: multipart/x-mixed-replace;boundary=section\r\n\r\n"); printf("--section\r\n"); //push内容的开始边界,服务器进行识别 for(i = 0; i < 10000; i++) { printf("Content-type: text/plain\r\n\r\n"); //指定内容的类型 printf("i = %d\n", i); printf("--section\n"); //下一次内容开始