加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
server.c 2.29 KB
一键复制 编辑 原始数据 按行查看 历史
爆裂键盘手 提交于 2024-02-26 02:44 . 完成本地pcm文件语音识别
/*
* @Author: 爆裂键盘手 1099404409@qq.com
* @Date: 2024-02-25 19:59:36
* @LastEditors: 爆裂键盘手 1099404409@qq.com
* @LastEditTime: 2024-02-25 22:51:01
* @FilePath: /simple-libwebsockets-example/server.c
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
#include <libwebsockets.h>
#include <string.h>
#include <stdio.h>
static int callback_http( struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len )
{
switch( reason )
{
case LWS_CALLBACK_HTTP:
lws_serve_http_file( wsi, "example.html", "text/html", NULL, 0 );
break;
default:
break;
}
return 0;
}
#define EXAMPLE_RX_BUFFER_BYTES (10)
struct payload
{
unsigned char data[LWS_SEND_BUFFER_PRE_PADDING + EXAMPLE_RX_BUFFER_BYTES + LWS_SEND_BUFFER_POST_PADDING];
size_t len;
} received_payload;
static int callback_example( struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len )
{
switch( reason )
{
case LWS_CALLBACK_RECEIVE:
memcpy( &received_payload.data[LWS_SEND_BUFFER_PRE_PADDING], in, len );
received_payload.len = len;
lws_callback_on_writable_all_protocol( lws_get_context( wsi ), lws_get_protocol( wsi ) );
break;
case LWS_CALLBACK_SERVER_WRITEABLE:
lws_write( wsi, &received_payload.data[LWS_SEND_BUFFER_PRE_PADDING], received_payload.len, LWS_WRITE_TEXT );
break;
default:
break;
}
return 0;
}
enum protocols
{
PROTOCOL_HTTP = 0,
PROTOCOL_EXAMPLE,
PROTOCOL_COUNT
};
static struct lws_protocols protocols[] =
{
/* The first protocol must always be the HTTP handler */
{
"http-only", /* name */
callback_http, /* callback */
0, /* No per session data. */
0, /* max frame size / rx buffer */
},
{
"example-protocol",
callback_example,
0,
EXAMPLE_RX_BUFFER_BYTES,
},
{ NULL, NULL, 0, 0 } /* terminator */
};
int main( int argc, char *argv[] )
{
struct lws_context_creation_info info;
memset( &info, 0, sizeof(info) );
info.port = 8000;
info.protocols = protocols;
info.gid = -1;
info.uid = -1;
struct lws_context *context = lws_create_context( &info );
while( 1 )
{
lws_service( context, /* timeout_ms = */ 0 );
}
lws_context_destroy( context );
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化