mongoose 嵌入web服务器 例子

mongoose 嵌入web服务器 例子

参考:

https://blog.csdn.net/wowocpp/article/details/116206013

settings_panel_for_a_device

./settings_panel
Starting device configurator on port 8000
mongoose 嵌入web服务器 例子_第1张图片

./multithreaded

Started on port 8000

mongoose 嵌入web服务器 例子_第2张图片

mongoose 嵌入web服务器 例子_第3张图片

publish_subscribe

./publish_subscribe 8000 server

Starting pubsub server on port 8000
New client connected from 192.168.99.219:55907
New client connected from 192.168.99.219:52381
New client connected from 192.168.99.219:49577
New client connected from 192.168.99.219:51166
New client connected from 192.168.99.219:49899

通过浏览器输入如下网址:
http://192.168.99.31:8000/

./restful_client

Starting RESTful client against http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=cesanta

Server closed connection

RESTful server host and request URI

./cookie_auth

Starting web server on port 8000
Starting web server on port 8000
user logged in, sid 25690a82c6be15f2
user (sid 25690a82c6be15f2) requested /
Session 25690a82c6be15f2 (user) closed due to idleness.

mongoose 嵌入web服务器 例子_第4张图片
分别输入:
user
password
mongoose 嵌入web服务器 例子_第5张图片

restful_server

Starting RESTful server on port 8000, serving .

mongoose 嵌入web服务器 例子_第6张图片

./mqtt_broker

MQTT broker started on 0.0.0.0:1883
USER HANDLER GOT EVENT 1
USER HANDLER GOT EVENT 3
USER HANDLER GOT EVENT 201
USER HANDLER GOT EVENT 4
USER HANDLER GOT EVENT 3
USER HANDLER GOT EVENT 203
USER HANDLER GOT EVENT 3
USER HANDLER GOT EVENT 203
USER HANDLER GOT EVENT 3
USER HANDLER GOT EVENT 203
USER HANDLER GOT EVENT 3
USER HANDLER GOT EVENT 212

win7 下面

mongoose 嵌入web服务器 例子_第7张图片
设置
mongoose 嵌入web服务器 例子_第8张图片
断开连接的时候 有点问题
比较慢

connected_device_3

Starting web server on port 8000

mongoose 嵌入web服务器 例子_第9张图片

connected_device_4

mongoose 嵌入web服务器 例子_第10张图片

udp_client

./udp_client 192.168.99.219:60000 55555

mongoose 嵌入web服务器 例子_第11张图片

这个是干啥 不懂

mongoose 嵌入web服务器 例子_第12张图片
224.1.1.1
65000

nc

./nc 192.168.99.219:60000

mongoose 嵌入web服务器 例子_第13张图片

websocket_chat

/home/sama5d2/general_work/http_web_server/mongoose/mongoose-6.18/examples/websocket_chat

./websocket_chat
Started on port 8000
192.168.99.219:50468 ++ joined
192.168.99.219:50468 1111
33333
127.0.0.1:60248 ++ joined
127.0.0.1:60248 9999
192.168.99.219:50468 ok
127.0.0.1:60248 hello

mongoose 嵌入web服务器 例子_第14张图片

websocket_chat_client

websocket_chat 运行的同时
同一个机器上,运行下面的程序:

./websocket_chat_client
-- Connected
192.168.99.219:65479 ++ joined
192.168.99.219:65479 -- left
192.168.99.219:54058 ++ joined
1111
192.168.99.219:54058 55555

2个网页端 和1个客户端 之间互相通信
相当于聊天室 群聊

sntp_client

同步时间

static const char *s_default_server = “pool.ntp.org”;

sntp_client
Local time: Thu Apr 29 15:32:44 2021
Time from pool.ntp.org: Thu Apr 29 15:32:45 2021

dashboard

mongoose 嵌入web服务器 例子_第15张图片
make clean
make
在这里插入图片描述

live-log

mongoose 嵌入web服务器 例子_第16张图片

websocket-server

mongoose-7.2/examples/websocket-server
修改
在这里插入图片描述

cc …/…/mongoose.c -I…/… -W -Wall -DMG_ENABLE_LINES=1 -DMG_ENABLE_DIRECTORY_LISTING=1 -o example main.c
./example
2021-04-29 08:06:00 I sock.c:469:mg_listen 1 accepting on http://0.0.0.0:8000

// Example Websocket server. Usage:
// 1. Start this server, type make
// 2. Open https://www.websocket.org/echo.html in your browser
// 3. In the “Location” text field, type ws://127.0.0.1:8000/websocket

http://coolaf.com/tool/chattest

mongoose 嵌入web服务器 例子_第17张图片

怎么同时启动一个 别的进程提供数据呢?

multithreaded.c 和 websocket_chat 结合一下
或者和 nc 结合一下
mg_start_thread
mg_broadcast
都是啥意思

big_upload

Starting web server on port 8000

mongoose 嵌入web服务器 例子_第18张图片

video-stream

2021-04-30 02:18:54 I mongoose.c:3056:mg_listen 1 accepting on http://0.0.0.0:8000

mongoose 嵌入web服务器 例子_第19张图片

curl 192.168.99.31:8000/api/video1
mongoose 嵌入web服务器 例子_第20张图片

mongoose 嵌入web服务器 例子_第21张图片

3.2 版本接口 — 2012年

void
mg_stop(struct mg_context *ctx)
{
	ctx->stop_flag = 1;

	/* Wait until mg_fini() stops */
	while (ctx->stop_flag != 2)
		(void) sleep(1);

	assert(ctx->num_threads == 0);
	free(ctx);

#if defined(_WIN32)
	(void) WSACleanup();
#endif /* _WIN32 */
}



struct mg_context *
mg_start(void)
{
	struct mg_context	*ctx;
	const struct mg_option	*option;

#if defined(_WIN32)
	WSADATA data;
	WSAStartup(MAKEWORD(2,2), &data);
#endif /* _WIN32 */

	if ((ctx = (struct mg_context *) calloc(1, sizeof(*ctx))) == NULL) {
		cry(fc(ctx), "cannot allocate mongoose context");
		return (NULL);
	}

	/* Initialize options. First pass: set default option values */
	for (option = known_options; option->name != NULL; option++)
		ctx->options[option->index] = option->default_value == NULL ?
			NULL : mg_strdup(option->default_value);

	/* Call setter functions */
	for (option = known_options; option->name != NULL; option++)
		if (option->setter != NULL &&
		    ctx->options[option->index] != NULL)
			if (option->setter(ctx,
			    ctx->options[option->index]) == FALSE) {
				mg_fini(ctx);
				return (NULL);
			}

	DEBUG_TRACE((DEBUG_MGS_PREFIX "%s: root [%s]",
	    __func__, ctx->options[OPT_ROOT]));

#if !defined(_WIN32)
	/*
	 * Ignore SIGPIPE signal, so if browser cancels the request, it
	 * won't kill the whole process.
	 */
	(void) signal(SIGPIPE, SIG_IGN);
#endif /* _WIN32 */

	(void) pthread_rwlock_init(&ctx->rwlock, NULL);
	(void) pthread_mutex_init(&ctx->mutex, NULL);
	(void) pthread_cond_init(&ctx->thr_cond, NULL);
	(void) pthread_cond_init(&ctx->empty_cond, NULL);
	(void) pthread_cond_init(&ctx->full_cond, NULL);

	/* Start master (listening) thread */
	start_thread(ctx, (mg_thread_func_t) master_thread, ctx);

	return (ctx);
}

你可能感兴趣的:(linux_arm,web_html)