0

I've used libwebsockets to develop a server that enable to use a simple linux terminal through a web page. Now i need to edit my code so that the server accept multiple clients. I didn't really understood how this library manage the structs to store client information so that I'm able to recognize each client request.

This is what i've got so far for single client:

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;

Can someone give me a good advice or some material to study (official API are too complicated)

Thanks in advance

  • 1
    If the official API is too complicated then I suggest going back to basics and learning how to RTFM – zerohero Nov 13 '17 at 14:15
  • *Shameless Plug*: did you consider using [facil.io](http://facil.io)? It's younger, with less features (no TLS/SSL or HTTP/2), but it's designed with ease of use in mind (simpler API) and for high concurrency loads (using `epoll` on Linux or `kqueue` on BSD, no Windows support). It also offers a built-in Pub/Sub engine, making it very idiomatic for Websockets. (I'm biased) – Myst Nov 19 '17 at 01:20

1 Answers1

0

Libwebsockets is singlethreaded and as a consequence, can not support multiple clients.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '22 at 02:57
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31261981) – beeselmane Mar 14 '22 at 18:51