当前位置:网站首页>使用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
边栏推荐
- Basic Terms of Machine Learning
- 蓝桥杯嵌入式备赛
- 【工具使用】Keil5软件使用-基础使用篇
- 堆(heap)系列_0x09:堆破坏示例(非法访问+未初始化+堆句柄不匹配)
- 软件安全内存区域详解
- 杭州富阳科目三新规3号线考试攻略
- 【工具使用】Modbus Slave软件使用详解
- Vim实用技巧_0.vim - introduction
- Analytic Hierarchy Process (AHP) - Applications of MATLAB in Mathematical Modeling (2nd Edition)
- Basic Concepts of Software Security
猜你喜欢
随机推荐
图像质量指标:峰值信噪比PSNR和结构相似性SSIM
交叉编译 Crypto++
关于sql语句中union和or的区别
【力扣】516. 最长回文子序列
NiN(Network in Network) pytorch实现
【工具使用】Keil软件包——知识宝藏库
Correlation analysis
【Postgraduate Work Weekly】(The third week)
Monte Carlo simulation
Unity UI框架思路与实现
【力扣】17. 电话号码的字母组合
【力扣】1154. 一年中的第几天
SQLMap常用命令介绍
Vim practical skills_0.vim - introduction
图解转置卷积原理
杭州富阳科目三新规3号线考试攻略
如何不使用第三个变量来交换两个数的值
事务的隔离级别
Face recognition sample code analysis (2) - face recognition analysis
图论最短路径求解









