{"id":18980708,"url":"https://github.com/niamtokik/distributed-space-invader","last_synced_at":"2025-04-19T19:13:59.924Z","repository":{"id":181202094,"uuid":"149163757","full_name":"niamtokik/distributed-space-invader","owner":"niamtokik","description":"Distributed Space Invader in Erlang, forward data across all nodes.","archived":false,"fork":false,"pushed_at":"2018-09-30T14:27:08.000Z","size":45,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-16T15:15:19.129Z","etag":null,"topics":["coding-dojo","erlang","forwarder"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/niamtokik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-09-17T17:38:31.000Z","updated_at":"2021-02-03T09:36:05.000Z","dependencies_parsed_at":"2023-07-14T13:39:49.155Z","dependency_job_id":null,"html_url":"https://github.com/niamtokik/distributed-space-invader","commit_stats":null,"previous_names":["niamtokik/distributed-space-invader"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niamtokik%2Fdistributed-space-invader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niamtokik%2Fdistributed-space-invader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niamtokik%2Fdistributed-space-invader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niamtokik%2Fdistributed-space-invader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niamtokik","download_url":"https://codeload.github.com/niamtokik/distributed-space-invader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249774563,"owners_count":21323634,"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":["coding-dojo","erlang","forwarder"],"created_at":"2024-11-08T16:07:34.455Z","updated_at":"2025-04-19T19:13:59.906Z","avatar_url":"https://github.com/niamtokik.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# distributed-space-invader\n\nDistributed Space Invader is a simple game state forwarder based only\nwith built-in Erlang datastructure. Client sent data with BERT, this\nserver will forward them to all other notes.\n\n## Build\n\n    $ rebar3 compile\n\n## Play with a shell\n\nIf you want to see what's going on in the VM during playing:\n\n    $ rebar3 shell -name ${name}@${ip}\n    \u003e application:start(spaceinvader).\n    \u003e net_kernel:connect_node('othernode@otherip').\n\n## Start it manually\n\nIf you want to create a full executable file, you can create an\nescript file with escriptize command\n\n    $ rebar3 escriptize\n    $ ./_build/bin/spaceinvader\n\n## Generate documentation\n\nA bunch of documentation was created, you can access them in directory\n`doc` after compiling it with this command:\n\n    $ rebar3 edoc\n\n## Haskell Space Invader Client\n\nOur own client is actually present here:\n\n    $ stack build\n    $ stack exec game \"username\"\n\n * https://github.com/lambda-rennes/space-invaders\n\n# Project history and steps\n\nThis project is to show that Erlang language is not only a language:\nwhen you install it, Erlang give you lot of integrated tools to do lot\nof things without installing external modules or libraries. This\nproject will introduce\n\n * Concise introduction to Erlang syntax\n * Live testing with Erlang REPL\n * Simple rebar3 use case\n * Small introduction to Distributed Erlang\n * Small introduction to OTP\n\n```\n         [bert datastructure]                      [accepted connection]\n  ______/                __________     __________/    _______\n |      |               |          |   |          |   |       |\n | game |--[tcp/7777]--\u003e| listener |--\u003e| acceptor |--\u003e| relay |--//\n |______|               |__________|   |__________|   |_______|\n                        /                             /\n    [tcp socket handler]                             /\n                              [message relay process]\n\n\n\n             [distributed erlang]\n     _______/    _______     __________                  ______\n    (       )   |       |   |          |                |      |\n --( cluster )-\u003e| relay |--\u003e| acceptor |---[tcp/7777]--\u003e| game |\n    (_______)   |_______|   |__________|                |______|\n        |                              \\\n        .                               [send ETF flow]\n     ___.___\n    :       :\n    : relay :\n    :_______:\n    \n```\n\nHere the detailed steps:\n\n1. Ensure your have all required Erlang tools on your system\n\n   ```\n   # On FreeBSD\n   pkg install erlang rebar3\n   ```\n   \n   If, for some reasons, those requirements are not available on your\n   distribution, source code and binary version of Erlang can be\n   downloaded directly from the official website:\n   http://www.erlang.org/downloads.\n\n2. Create a repository on github (or locally with github or fossil or\n   whatever you want)\n   \n   ```\n   git init spaceinvaders\n   ```\n   \n3. We can now use rebar3, this tool will initialize our project with\n   some default files and templates, make things easier for everyone.\n   \n   ```\n   rebar3 new app name=spaceinvaders\n   cd spaceinvaders\n   git add LICENSE README.md\n   git add rebar.config\n   git add src/*.erl\n   git add src/*.src\n   git commit -m \"our first commit\"\n   ```\n   \n   * `LICENSE` and `README.md` don't need any explaination.\n   \n   * `rebar.config` is our configuration for our project.\n   \n   * `src/spaceinvader_app.erl` will contain our Erlang application\n     code. (http://erlang.org/doc/apps/kernel/application.html)\n   \n   * `src/spaceinvader.app.src` is our resource file, this is a kind\n     of checker/starter for our app. (http://erlang.org/doc/man/app.html)\n\t \n   * `src/spaceinvader_sup.erl` is our main supervisor for our\n     application, this one will monitor our application and restart it\n     automatically if this one crash. (http://erlang.org/doc/man/supervisor.html)\n\t \n   * `src/*.erl` all other files, can be libraries, other application...\n\n4. So, actually, we want an application to manage tcp socket and\n   forward all messages to other client, based on Distributed\n   Erlang. To make this thing possible, we'll, first, create our\n   listener and acceptor. (I don't want to reuse code from other\n   project, but, if you are interested, you can take a look at ranch,\n   this application manage a pool of tcp acceptor, mainly used in\n   cowboy http server). So, we'll create a file named\n   `src/spaceinvader_listener.erl`. This process\n   \n   * listen a defined tcp port localy (7777 in our case)\n   * spawn a new acceptor when a connection is accepted\n   * keep state of our connection\n   \n   ```\n   ```\n   \n   And `src/spaceinvader_acceptor.erl` for our acceptor side.\n   \n   * accept messages from the accepted socket\n   * route messages\n   \n   ```\n   \n   ```\n   \n   We will also use Distributed Erlang feature, we should enable it in\n   `rebar.config`. (https://www.rebar3.org/docs/configuration#section-distribution)\n   \n   ```\n   { dist_node\n   , [{setcookie, 'mycookie'}\n     ,{sname, 'nodename@localhost'}\n     ]\n   }.\n   ```\n\n   NOTE: each player must choose a different name and hostname.\n\n   Its a good moment to try and see if our code is compiling and\n   working as expected, first, we build our project with rebar3 and\n   start an Erlang REPL. (https://www.rebar3.org/docs/commands#section-shell)\n   \n   ```\n   rebar3 compile\n   rebar3 shell\n   ```\n   \n   In the new opened shell, we can start manually our listener\n   \n   ```\n   spaceinvader_listener:start().\n   ```\n   \n   In another shell console session, we can send some raw tcp data\n   with netcat.\n   \n   ```\n   echo \"test\" | nc localhost 7777\n   ```\n\n5. Now is the \"complicated\" part, for your information, this part is\n   not really safe for different reason, and should be used for\n   testing purpose only. Distributed Erlang feature offer you a way to\n   connect Erlang nodes between them but, without a lot of\n   security. We'll see that later. For the moment, we'll create a new\n   file named `src/spaceinvader_relay.erl`. This file will give us a\n   common interface to talk to other connected nodes.\n   \n   ```\n   ```\n   \n   We can rebuild our code directly from rebar3 shell and start our\n   relay.\n   \n   ```\n   r3:do(compile).\n   spaceinvader_relay:start().\n   ```\n\n   This process should be registered and will receive all messages\n   from all other nodes...\n   \n   ```\n   Msg = \"This is a test\".\n   {'myname', 'myhostname'} ! Msg.\n   ```\n\n   ... and relay it to our game.\n\n\n----\n\n   * http://erlang.org/doc/reference_manual/distributed.html\n   * http://erlang.org/doc/man/net_kernel.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniamtokik%2Fdistributed-space-invader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniamtokik%2Fdistributed-space-invader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniamtokik%2Fdistributed-space-invader/lists"}