当前位置:网站首页>使用libwebsockets搭建一个简单的websocket服务器
使用libwebsockets搭建一个简单的websocket服务器
2022-08-09 15:00:00 【北雨南萍】
本文讲解如何开发一个简单的WebSocket服务器
如果你嫌这两个例子都太简单了,且想了解更多更深的websocket的工作原理,
可以看这篇文章:http://lucumr.pocoo.org/2012/9/24/websockets-101/
为了让这个例子足够简单,我们将对所有的请求以逆序做为响应,
例如,我们们发送"Hello, world!", 那么它的响应就是"!dlrow ,olleH"。
1 WebSocket server
STEP1.
The first part is very similar to the web server, but since we don't want to handle any HTTP requests
the callback_http may be stay empty.
第一部分和页面服务器很类似,只是我们不需要处理任何HTTP请求,
所以回调函数callback_http可以是空的。
static int callback_http(structlibwebsocket_context * this,
structlibwebsocket *wsi,
enumlibwebsocket_callback_reasons reason, void *user,
void *in, size_t len)
{
return 0;
}
The interesting part comes now. We need to handle each request
边栏推荐
猜你喜欢
随机推荐
Candide3 face animation model
【Postgraduate Work Weekly】(Week 5)
[Paper reading] LIME: Low-light Image Enhancement via Illumination Map Estimation (the most complete notes)
Heap series _0x02: The past and present of the heap (WinDbg+Visual Studio compilation)
hugging face tutorial - Chinese translation - sharing custom model
NiN(Network in Network) pytorch实现
【力扣】593. 有效的正方形
【力扣】1995. 统计特殊四元组
堆(heap)系列_0x05:一张图剖析堆块分配和FreeLists的联系
TCP/IP协议组——完整工作过程分析
输入不定长数组,输入一个字符串,既包含字符,又包含数字,输出数组,输入一个二维数组,字符和数字都可
【学习笔记】win10报0xc0000221错误无法开机
wireshark抓包新手使用教程
蒙特卡罗 Monte Carlo 模拟
相关性分析
如何通过Photoshop根据纹理贴图轻松获得法线贴图
灰色关联分析
【工具使用】Keil5软件使用-进阶工程配置篇
类定义中class和className中间的修饰词的作用有关问题
灰色关联度矩阵——MATLAB在数学建模中的应用