{"id":19869699,"url":"https://github.com/sockjs/sockjs-erlang","last_synced_at":"2025-04-07T10:26:54.386Z","repository":{"id":1694900,"uuid":"2423306","full_name":"sockjs/sockjs-erlang","owner":"sockjs","description":"WebSocket emulation - Erlang server ","archived":false,"fork":false,"pushed_at":"2017-04-04T14:20:17.000Z","size":1059,"stargazers_count":269,"open_issues_count":19,"forks_count":120,"subscribers_count":38,"default_branch":"master","last_synced_at":"2024-04-15T14:09:05.157Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://sockjs.org","language":"Erlang","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/sockjs.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-09-20T15:29:11.000Z","updated_at":"2023-10-30T04:34:11.000Z","dependencies_parsed_at":"2022-09-11T02:51:34.418Z","dependency_job_id":null,"html_url":"https://github.com/sockjs/sockjs-erlang","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fsockjs-erlang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fsockjs-erlang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fsockjs-erlang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fsockjs-erlang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sockjs","download_url":"https://codeload.github.com/sockjs/sockjs-erlang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247634334,"owners_count":20970511,"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":"2024-11-12T16:06:38.754Z","updated_at":"2025-04-07T10:26:54.362Z","avatar_url":"https://github.com/sockjs.png","language":"Erlang","funding_links":[],"categories":["Tools per Language"],"sub_categories":["Erlang"],"readme":"SockJS family:\n\n  * [SockJS-client](https://github.com/sockjs/sockjs-client) JavaScript client library\n  * [SockJS-node](https://github.com/sockjs/sockjs-node) Node.js server\n  * [SockJS-erlang](https://github.com/sockjs/sockjs-erlang) Erlang server\n\n\nSockJS-erlang server\n====================\n\n[SockJS](http://sockjs.org) server written in Erlang. Can run with\n[Cowboy](https://github.com/extend/cowboy) http server. SockJS-erlang\nis in core web-framework agnostic (up to version\n[v0.2.1](https://github.com/sockjs/sockjs-erlang/tree/v0.2.1 ) we also\nsupported\n[Misultin](https://github.com/ostinelli/misultin)). SockJS-erlang is\ncompatible with\n[SockJS client version 0.3](http://sockjs.github.com/sockjs-protocol/sockjs-protocol-0.3.html). See\nhttps://github.com/sockjs/sockjs-client for more information on\nSockJS.\n\n\nShow me the code!\n-----------------\n\nA simplistic echo SockJS server using Cowboy may look more or less\nlike this:\n\n```erlang\nmain(_) -\u003e\n    ok = application:start(xmerl),\n    ok = application:start(sockjs),\n    ok = application:start(ranch),\n    ok = application:start(crypto),\n    ok = application:start(cowboy),\n\n    SockjsState = sockjs_handler:init_state(\n                    \u003c\u003c\"/echo\"\u003e\u003e, fun service_echo/3, state, []),\n\n    Routes = [{'_',  [{\u003c\u003c\"/echo/[...]\"\u003e\u003e,\n                       sockjs_cowboy_handler, SockjsState}]}],\n    Dispatch = cowboy_router:compile(Routes),\n\n    cowboy:start_http(cowboy_test_http_listener, 100,\n                      [{port, 8081}],\n                      [{env, [{dispatch, Dispatch}]}]),\n    receive\n        _ -\u003e ok\n    end.\n\nservice_echo(_Conn, init, state)          -\u003e {ok, state};\nservice_echo(Conn, {recv, Data}, state)   -\u003e Conn:send(Data);\nservice_echo(_Conn, {info, _Info}, state) -\u003e {ok, state};\nservice_echo(_Conn, closed, state)        -\u003e {ok, state}.\n```\n\nDig into the `examples` directory to get working code:\n\n  * https://github.com/sockjs/sockjs-erlang/examples/cowboy_echo.erl\n\n\nHow to run the examples?\n------------------------\n\nYou may need a recent version of Erlang/OTP, at least R14B is recommended.\n\nTo run Cowboy example:\n\n    cd sockjs-erlang\n    ./rebar get-deps\n    ./rebar compile\n    ./examples/cowboy_echo.erl\n\nThis will start a simple `/echo` SockJS server on\n`http://localhost:8081`.  Open this link in a browser and play\naround.\n\n\nSockJS-erlang API\n-----------------\n\nExcept for the web framework-specific API's, SockJS-erlang is rather\nsimple. It has just a couple of methods:\n\n * **sockjs_handler:init_state(prefix, callback, state, options) -\u003e service()**\n\n    Initializes the state of a SockJS service (ie: a thing you can\n    access from the browser, it has an url and a code on the server\n    side). `prefix` is a binary that must exacty match the url prefix\n    of the service, for example, if service will be listening on\n    '/echo', this parameter must be set to `\u003c\u003c\"/echo\"\u003e\u003e`. `callback`\n    function will be called when a new SockJS connection is\n    established, data received or a connection is closed. The value of\n    `state` will be passed to the callback and preserved if returned\n    value has changed. Options is a proplist that can contain\n    following tuples:\n\n     * `{sockjs_url, string()}` - Transports which don't support\n       cross-domain communication natively ('eventsource' to name one)\n       use an iframe trick.  A simple page is served from the SockJS\n       server (using its foreign domain) and is placed in an invisible\n       iframe. Code run from this iframe doesn't need to worry about\n       cross-domain issues, as it's being run from domain local to the\n       SockJS server. This iframe also does need to load SockJS\n       javascript client library, and this option lets you specify its\n       url (if you're unsure, point it to \u003ca\n       href=\"http://cdn.sockjs.org/sockjs-0.2.min.js\"\u003e the latest\n       minified SockJS client release\u003c/a\u003e, this is the default).\n     * `{websocket, boolean()}` - are native websockets enabled? This\n       can be usefull when your loadbalancer doesn't support them.\n     * `{cookie_needed, boolean()}` - is your load balancer relying on\n       cookies to get sticky sessions working?\n     * `{heartbeat_delay, integer()}` - how often to send heartbeat\n       packets (in ms).\n     * `{disconnect_delay, integer()}` - how long to hold session state\n       after the client was last connected (in ms).\n     * `{response_limit, integer()}` - the maximum size of a single\n       http streaming response (in bytes).\n     * `{logger, fun/3}` - a function called on every request, used\n       to print request to the logs (or on the screen by default).\n\n    For more explanation, please do take a look at\n    [SockJS-node readme](https://github.com/sockjs/sockjs-node/blob/master/README.md).\n\n * **Connection:send(payload) -\u003e ok**\n\n     Send data over an active SockJS connection. Payload should be of\n     iodata() type. Messages sent after connection gets closed will be\n     lost.\n\n * **Connection:close(code, reason) -\u003e ok**\n\n     Close an active SockJS connection with code and reason. If code\n     and reason are skipped, the defaults are used.\n\n * **Connection:info() -\u003e proplist()**\n\n     Sometimes you may want to know more about the underlying\n     connection. This method returns a proplist with few attributes\n     extracted from the first HTTP/websocket request that was coming\n     to this connection. You should see:\n\n       * peername - ip address and port of the remote host\n       * sockname - ip address and port of the local endpoint\n       * path - the path used by the request that started the connection\n       * headers - a set of headers extracted from the request that\n         may be handy (don't expect to retrieve Cookie header).\n\n\nThe framework-specific calls are more problematic. Instead of trying\nto explain how to use them, please take a look at the examples.\n\n * **type(req() :: {cowboy, request()})**\n * **sockjs_handler:handle_req(service(), req()) -\u003e req()**\n * **sockjs_handler:handle_ws(service(), req()) -\u003e req()**\n\n\nStability\n---------\n\nSockJS-erlang is quite new, but should be reasonably stable. Cowboy is passes all the\n[SockJS-protocol tests](https://github.com/sockjs/sockjs-protocol).\n\nDeployment and load balancing\n-----------------------------\n\nSockJS servers should work well behind many load balancer setups, but\nit sometimes requres some additional twaks.  For more details, please\ndo take a look at the 'Deployment' section in\n[SockJS-node readme](https://github.com/sockjs/sockjs-node/blob/master/README.md).\n\n\nDevelopment and testing\n-----------------------\n\nYou need [rebar](https://github.com/basho/rebar)\n([instructions](https://github.com/basho/rebar/wiki/Building-rebar)).\nDue to a bug in rebar config handling you need a reasonably recent\nversion - newer than late Oct 2011. Alternatively, SockJS-erlang is\nbundeled with a recent rebar binary.\n\nSockJS-erlang contains a `test_server`, a simple server used for\ntesting.\n\nTo run Cowboy test_server:\n\n    cd sockjs-erlang\n    ./rebar get-deps\n    ./rebar compile\n    ./examples/cowboy_test_server.erl\n\nThat should start test_server on port 8081. Currently, there are two\nseparate test suits using test_server.\n\n### SockJS-protocol Python tests\n\nOnce test_server is listening on `http://localhost:8081` you may test it\nusing SockJS-protocol:\n\n    cd sockjs-protocol\n    make test_deps\n    ./venv/bin/python sockjs-protocol-dev.py\n\nFor details see\n[SockJS-protocol README](https://github.com/sockjs/sockjs-protocol#readme).\n\n### SockJS-client QUnit tests\n\nYou need to start a second web server (by default listening on 8080)\nthat is serving various static html and javascript files:\n\n    cd sockjs-client\n    make test\n\nAt that point you should have two web servers running: sockjs-erlang on\n8081 and sockjs-client on 8080. When you open the browser on\n[http://localhost:8080/](http://localhost:8080/) you should be able\nrun the QUnit tests against your sockjs-node server.\n\nFor details see\n[SockJS-client README](https://github.com/sockjs/sockjs-client#readme).\n\nAdditionally, if you're doing more serious development consider using\n`make serve`, which will automatically the server when you modify the\nsource code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsockjs%2Fsockjs-erlang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsockjs%2Fsockjs-erlang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsockjs%2Fsockjs-erlang/lists"}