0

我使用 libwebsockets 开发了一个服务器,可以通过网页使用简单的 linux 终端。现在我需要编辑我的代码,以便服务器接受多个客户端。我并没有真正理解这个库如何管理存储客户信息的结构,以便我能够识别每个客户请求。

这是我迄今为止为单个客户所拥有的:

int port = 8000;
const char *interface = NULL;
struct lws_context *context;
int opts = 0;
struct lws_context_creation_info info;
memset(&info, 0, sizeof info);
info.port = port;
info.iface = interface;
info.protocols = protocols;
info.ssl_cert_filepath = NULL;
info.ssl_private_key_filepath = NULL;
info.gid = -1;
info.uid = -1;
info.options = opts;
context = lws_create_context(&info);
if (context == NULL) {
 fprintf(stderr, "lws init failed\n");
 return -1;
}
printf("starting server...\n");
    buffer = malloc(sizeof(char) * LSH_RL_BUFSIZE);
    outbuf = malloc(sizeof(char) * OUT_BUFFER_SIZE);
    strcpy(outbuf,"Welcome to websocket terminal\n");
    while (1) {
        lws_service(context, 50);
}
lws_context_destroy(context);
return 0;

有人可以给我一个好的建议或者一些材料来学习(官方API太复杂)

提前致谢

4

0 回答 0