Add outbound websocket client mode (--connect)#1523
Open
semistrict wants to merge 5 commits intotsl0922:mainfrom
Open
Add outbound websocket client mode (--connect)#1523semistrict wants to merge 5 commits intotsl0922:mainfrom
semistrict wants to merge 5 commits intotsl0922:mainfrom
Conversation
Add --connect option that puts ttyd in client mode: instead of listening for incoming browser connections, ttyd connects outbound to a remote WebSocket server and bridges the local PTY to it. The remote endpoint receives terminal output and can send input using the same binary protocol. Usage: ttyd --connect ws://host:port/path -W <command>
Extract handle_writeable(), receive_append(), handle_command(), receive_cleanup(), and handle_close() as shared static helpers. Both callback_tty (server) and callback_tty_client use them, eliminating ~90 lines of duplication.
Node.js test that starts a WS server, connects ttyd in client mode, verifies bidirectional communication (OUTPUT sent, INPUT echoed back), and checks for clean disconnect. Run: cd test && npm install && node test-outbound.js [path-to-ttyd]
Enables `make test` / `ctest` which runs the Node.js e2e test against the built ttyd binary.
Adds a ttyd-sanitized build target (excluded from default build) and a test-sanitized custom target that builds it and runs the e2e tests under AddressSanitizer + UndefinedBehaviorSanitizer. Usage: cd build && cmake .. && make test-sanitized
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--connect <ws://url>option that puts ttyd in client mode: instead of listening for incoming browser connections, ttyd connects outbound to a remote WebSocket server and bridges the local PTY to itOUTPUT) and can send input (INPUT,RESIZE_TERMINAL,PAUSE,RESUME) using the same binary protocolws://andwss://(TLS) URLsUsage
Use cases
Changes
src/server.h: Addedconnect_urlfield toserverstructsrc/server.c: Added--connectCLI option, client protocol array, and client-mode branching inmain()(skips vhost creation, useslws_client_connect_via_info()instead)src/protocol.c: Extracted shared helpers (handle_writeable,receive_append,handle_command,handle_close) used by both server and client callbacks. Addedcallback_tty_client()for client-mode connectionstest/test-outbound.js: End-to-end test — starts a WS server, connects ttyd in client mode, verifies bidirectional OUTPUT/INPUT and clean disconnectTest plan
ttyd --helpshows the new--connectoption--connect) is unchangedwss://with TLS-enabled endpoint