{"id":28384441,"url":"https://github.com/runpod-workers/worker-websocket","last_synced_at":"2025-06-25T23:30:52.250Z","repository":{"id":278307849,"uuid":"935189970","full_name":"runpod-workers/worker-websocket","owner":"runpod-workers","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-19T04:14:29.000Z","size":14,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-30T09:27:29.803Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/runpod-workers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-19T03:39:11.000Z","updated_at":"2025-04-26T00:08:01.000Z","dependencies_parsed_at":"2025-02-19T04:39:05.760Z","dependency_job_id":null,"html_url":"https://github.com/runpod-workers/worker-websocket","commit_stats":null,"previous_names":["runpod-workers/worker-websocket"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/runpod-workers/worker-websocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runpod-workers%2Fworker-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runpod-workers%2Fworker-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runpod-workers%2Fworker-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runpod-workers%2Fworker-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/runpod-workers","download_url":"https://codeload.github.com/runpod-workers/worker-websocket/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runpod-workers%2Fworker-websocket/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261972491,"owners_count":23238536,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-30T08:38:39.981Z","updated_at":"2025-06-25T23:30:52.241Z","avatar_url":"https://github.com/runpod-workers.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serverless WebSocket Worker Example \n\nThis WebSocket worker example allows direct communication with a serverless worker without using RunPod’s default REST API. It enables real-time, bidirectional communication between a websocket client and the worker.\n\n## How It Works\n\n1. Wake up the worker – You must send a request(`https://api.runpod.ai/v2/endpointId/run`) to wake up the serverless worker.\n2. Retrieve the worker’s `public IP` and `TCP port` – Once the worker is awake, `handler` [function](https://github.com/runpod-workers/worker-websocket/blob/main/rp_handler.py#L52) will obtain worker's public IP and TCP port from the environment variables.\n3. Share connection details – Use [progress_update](https://docs.runpod.io/serverless/workers/handlers/handler-additional-controls#update-progress) to share the public IP and TCP port with any backend application that plans to communicate with the worker.\n4. Fetch connection details – Call `https://api.runpod.ai/v2/endpointId/status/request_id` to retrieve the public IP and TCP port.\n5. Establish a WebSocket connection – Use a [WebSocket client](https://github.com/runpod-workers/worker-websocket/blob/main/client.py) to connect to the worker using the obtained IP and port.\n6. Complete communication and shut down – Once the client or backend application is done, send a [shutdown signal](https://github.com/runpod-workers/worker-websocket/blob/main/client.py#L13), in this example, we are transmitting the string “shutdown”.\n7. Graceful termination – Upon receiving \"shutdown\", the WebSocket server will [shut down](https://github.com/runpod-workers/worker-websocket/blob/main/rp_handler.py#L19), the handler function will return, and the worker instance will be terminated.\n\n### Important Deployment Notes\n\n- After deploying this code, remember to go to Serverless Settings → Docker Configuration → Expose TCP Ports and expose port 8765, or whichever port your WebSocket server is running on.\n- If you choose a different port, ensure that you update the [environment variable name](https://github.com/runpod-workers/worker-websocket/blob/main/rp_handler.py#L53) accordingly, as the exposed port number is appended to the variable name.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunpod-workers%2Fworker-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frunpod-workers%2Fworker-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunpod-workers%2Fworker-websocket/lists"}