--readonly, -R Do not allow clients to write to the TTY
--client-option, -t Send option to client (format: key=value), repeat to add more options
--check-origin, -O Do not allow websocket connection from different origin
+ --max-clients, -m Maximum clients to support (default: 0, no limit)
--once, -o Accept only one client and exit on disconnection
--browser, -B Open terminal with the default system browser
--index, -I Custom index.html path
}
lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), name, sizeof(name), rip, sizeof(rip));
- lwsl_notice("HTTP %s - %s (%s)\n", in, rip, name);
+ lwsl_notice("HTTP %s - %s (%s)\n", (char *) in, rip, name);
switch (check_auth(wsi)) {
case 0:
lwsl_warn("refuse to serve WS client due to the --once option.\n");
return 1;
}
+ if (server->max_clients > 0 && server->client_count == server->max_clients) {
+ lwsl_warn("refuse to serve WS client due to the --max-clients option.\n");
+ return 1;
+ }
if (lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_GET_URI) <= 0 || strcmp(buf, WS_PATH)) {
lwsl_warn("refuse to serve WS client for illegal ws path: %s\n", buf);
return 1;
{"ssl-ca", required_argument, NULL, 'A'},
{"readonly", no_argument, NULL, 'R'},
{"check-origin", no_argument, NULL, 'O'},
+ {"max-clients", required_argument, NULL, 'm'},
{"once", no_argument, NULL, 'o'},
{"browser", no_argument, NULL, 'B'},
{"debug", required_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, 0, 0}
};
-static const char *opt_string = "p:i:c:u:g:s:r:I:aSC:K:A:Rt:OoBd:vh";
+static const char *opt_string = "p:i:c:u:g:s:r:I:aSC:K:A:Rt:Om:oBd:vh";
void print_help() {
fprintf(stderr, "ttyd is a tool for sharing terminal over the web\n\n"
" --readonly, -R Do not allow clients to write to the TTY\n"
" --client-option, -t Send option to client (format: key=value), repeat to add more options\n"
" --check-origin, -O Do not allow websocket connection from different origin\n"
+ " --max-clients, -m Maximum clients to support (default: 0, no limit)\n"
" --once, -o Accept only one client and exit on disconnection\n"
" --browser, -B Open terminal with the default system browser\n"
" --index, -I Custom index.html path\n"
case 'O':
server->check_origin = true;
break;
+ case 'm':
+ server->max_clients = atoi(optarg);
+ break;
case 'o':
server->once = true;
break;
lwsl_notice(" check origin: true\n");
if (server->readonly)
lwsl_notice(" readonly: true\n");
+ if (server->max_clients > 0)
+ lwsl_notice(" max clients: %d\n", server->max_clients);
if (server->once)
lwsl_notice(" once: true\n");
if (server->index != NULL) {