{"id":15370214,"url":"https://github.com/jedisct1/simple-comet-server","last_synced_at":"2025-04-15T13:52:42.548Z","repository":{"id":1149635,"uuid":"1033180","full_name":"jedisct1/Simple-Comet-Server","owner":"jedisct1","description":"HTTP long-polling server and javascript client library.","archived":false,"fork":false,"pushed_at":"2025-02-14T14:06:48.000Z","size":88,"stargazers_count":18,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T20:46:21.000Z","etag":null,"topics":["comet","javascript","long-polling","pubsub","python3"],"latest_commit_sha":null,"homepage":"https://github.com/jedisct1/Simple-Comet-Server","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jedisct1.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-10-28T21:05:44.000Z","updated_at":"2025-02-14T14:06:52.000Z","dependencies_parsed_at":"2022-08-16T12:15:25.590Z","dependency_job_id":null,"html_url":"https://github.com/jedisct1/Simple-Comet-Server","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedisct1%2FSimple-Comet-Server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedisct1%2FSimple-Comet-Server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedisct1%2FSimple-Comet-Server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedisct1%2FSimple-Comet-Server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jedisct1","download_url":"https://codeload.github.com/jedisct1/Simple-Comet-Server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249085474,"owners_count":21210267,"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":["comet","javascript","long-polling","pubsub","python3"],"created_at":"2024-10-01T13:40:24.791Z","updated_at":"2025-04-15T13:52:42.529Z","avatar_url":"https://github.com/jedisct1.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"A simple COMET server\n=====================\n\nThis is a minimalist HTTP long-polling server.\n\nWith intentionally no support for Websockets nor Bayeux.\n\nBut the compressed client-side Javascript library weights less than 500 bytes,\nwith support for multiple channels and cross-domain requests.\n\nIt should work just fine on most web browsers, including legacy ones and\nmobile browsers.\n\n\nInstallation\n------------\n\nThe server requires Python 3 and the Twisted framework.\n\nIt can be installed the boring way:\n\n```sh\ngit clone git://github.com/jedisct1/Simple-Comet-Server.git\ncd Simple-Comet-Server\nsudo python setup.py install\n```\n\nUsing simple_comet as a backend for a frontend server like Nginx is\nhighly recommended.\n\n\nServer switches\n---------------\n\n`simple_comet`\n\n    --http-port=\u003cHTTP server port\u003e (default=none)\n\nChange the HTTP port the server will listen to. Tests assume port 4080.\n\n    --unix-socket-path=\u003cpath to UNIX socket) (default=none)\n\nIn addition or in place of a TCP port, listen to a local UNIX socket.\n\n    --http-timeout=\u003cHTTP timeout in seconds\u003e (default=30)\n\nDrop inactive connections after this many seconds.\n\n    --session-timeout=\u003csession timeout in seconds\u003e (default=60)\n\nClear sessions after this many seconds.\n\n    --inactive-channel-timeout=\u003cinactive channel timeout\u003e (default=90)\n\nRemove channels with no clients after this many seconds.\n\n    --messages-per-channel=\u003cdefault max messages per channel\u003e (default=100)\n\nThe default number of messages to keep in every channel. When the\nqueue is full, the oldest message will get dropped in order to make\nspace for new messages.\n\n    --quote-json\n\nEncapsulate JSON responses with `/*-secure- ... */` comments.\n\n    --enable-status\n\nEnable /stats.json in order to monitor activity.\n\n\nREST API\n--------\n\nFor every resource, a `.json` suffix returns the result as a\nJSON-serialized object, while a `.jsonp` suffix returns a reply\nsuitable for a JSON-P request.\n\nThe default callback for JSON-P requests is `_JSONP_comet_cb()`.\nIt can be changed through the value of a `cb` variable added to the\nquery string, but the name must start with `_JSONP_`.\n\n\n* **Registering a channel**\n\nYour server-side application should probably handle this, not the\nclient.\n\n    Method: POST\n    URI: http://$HOST:$PORT/channels.json\n    Payload:\n    channel_id=(name of the new channel)\n    use_sessions=1: only registered clients can join the channel\n    max_messages=(non-default number of retained messages)\n\n\n* **Pushing data to a channel**\n\nStore a new message and forward it to subscribers.\n\n    Method: POST\n    URI: http://$HOST:$PORT/channels/(channel name).json\n    Payload:\n    content=(message content)\n\n\n* **Registering a client**\n\nYour server-side application should probably handle this, not the\nclient.\nRegistered clients can join non-anonymous channels.\nRegistering a client is not required in order to subscribe to\nanonymous channels.\n\n    Method: POST\n    URI: http://$HOST:$PORT/clients.json\n    Payload:\n    client_id=(unique client identifier)\n\n\n* **Monitoring the server**\n\nOnly available if --enable-status has been enabled.\n\n    Method: GET\n    URI: http://$HOST:$PORT/status.json\n\n\n* **Reading data from channels**\n\nThis should be sent by your server-side application.\n\n    Method: GET\n    URI: http://$HOST:$PORT/channels/(channels list).json\n    Query string:\n    client_id=(client identifier): only required for non-anonymous channels\n    since=(identifier of the last read frame)\n\nMultiple channels can be subscribed to, and anonymous and non-anonymous\nchannels can be mixed. Just use a pipe (`%7C`) as a delimiter.\n\nThe reply looks like:\n\n```json\n    { \"since\": 0,\n      \"messages\": {\n        \"channelA\": [\n          { \"content\": \"message1\",\n            \"id\": 128916015846785,\n            \"ts\": 1289160231\n          }\n        ],\n        \"channelB\": [\n          { \"content\": \"message1\",\n            \"id\": 128916015846787,\n            \"ts\": 1289160237\n          },\n          { \"content\": \"message2\",\n            \"id\": 128916015846786,\n            \"ts\": 1289160235\n          }\n        ]\n      },\n      \"return_code\": 1,\n      \"error_message\": \"\",\n      \"last_id\": 128916015846785\n    }\n```\n\n`last_id` is the identifier of the last frame. The following request\nshould include it as the value for `since`.\nThe first request may omit this or use 0.\n\n* **Deleting a channel**\n\nSend a `DELETE` query to the channel URI:\n\n    Method: DELETE\n    URI: http://$HOST:$PORT/channels/(channel name).json\n\n\nJavascript API\n--------------\n\nThe Javascript library (`client/simple-comet.js`) is designed to query a single server, through JSON-P.\n\nSubscribing to channels:\n\n```js\nSimpleComet.subscribe(url, callback, client_id)\n```\n\n`client_id` is only required in order to subscribe to non-anonymous\nchannels.\n\nThe callback function will be called every time a watched channel will\nbe updated.\n\nStarting the engine:\n\n```js\nSimpleComet.start()\n```\n\nYou usually want to call this function when the DOM is ready.\nCalls to SimpleComet.subscribe() can be made after or before this one.\n\n\nUsing Nginx and local sockets\n-----------------------------\n\nNginx can proxy to local UNIX sockets. If Nginx and the Comet server\nare hosted on the same server, this is the recommended way to make\nthem play well.\n\nStart the Comet server with something like:\n\n    simple-comet --enable-status --unix-socket=/var/tmp/comet.sock\n\nAnd define an Nginx virtual host like:\n\n    server {\n      listen 80;\n      server_name comet.example.com;\n      root /var/empty/;\n\n      location / {\n        return 404;\n      }\n\n      location /subscribe/ {\n        add_header Access-Control-Allow-Origin \"*\";\n        add_header Access-Control-Allow-Methods \"GET, OPTIONS\";\n        add_header Access-Control-Allow-Headers \"X-Requested-With,Accept,If-Modified-Since,ETag\";\n        add_header Access-Control-Max-Age \"1728000\";\n\n        proxy_pass http://unix:/var/tmp/comet.sock:/channels/;\n      }\n    }\n\n`add_headers` are for CORS (cross-domain without JSON-P) requests.\nYou don't need these if you only intend to use the provided Javascript library.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedisct1%2Fsimple-comet-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjedisct1%2Fsimple-comet-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedisct1%2Fsimple-comet-server/lists"}