WebSocket -- Mongoose

来源:互联网 发布:cg用什么软件 编辑:程序博客网 时间:2024/06/01 10:40

1.简介
    Mongoose Embedded Web Server Library - Mongoose is more than an embedded webserver. It is a multi-protocol embedded networking library with functions including TCP, HTTP client and server, WebSocket client and server and much more. https://www.cesanta.com

mongoose是轻量级的socket服务,因此在带宽较低,网络传输条件不稳定的IOT(物联网)领域,得到广泛应用。

2.Download
    https://github.com/cesanta/mongoose

3.the first websocket Example
    big_upload         将文件上载到web
big_upload

4.运行及测试
~/mongoose/examples/big_upload$ ./big_upload

打开浏览器,输入http://127.0.0.1:8080/

可以看到以下页面

web

上传文件之后,页面跳转

这里写图片描述

此时,我们来看看port 8080的连接状态     使用 netstat 命令
这里写图片描述


5.总结
    WebSocket很有意思,不是吗?可以用来传输文件,传输消息。我想到一个,web peer to peer 传输文件。WebSocket的重头戏在 IOT。Mongoose是一款优秀的开源库。

这里写图片描述

优秀的作品由负责的团体维护。


#define error https://github.com/cesanta/mongoose/issues/713
本来在mongoose.h 中#define的变量在big_upload中未定义。因为mongoose.h 未编译。makefile编写有问题。

copy mongoose.c mongoose.h to your own project.

问题:big_uuload独立调用mongoose.h , mongoose.c, 执行.exe, Web端上传文件及其慢。为什么?

because mongoose do not compilation.

Makefile is important. like this

  1 source = big_upload.c mongoose.c  2   3 main:$(source)  4         gcc $(source) -o main -DMG_ENABLE_HTTP_STREAMING_MULTIPART  5   6 .PHONY: clean  7 clean:  8         -rm main *.o

From: https://github.com/cesanta/mongoose/issues/713

0 0