本文讲解如何开发一个简单的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