Skip to content

Instantly share code, notes, and snippets.

@cybrox
Last active July 17, 2018 16:00
Show Gist options
  • Save cybrox/c0f4f55dad55a86bb0e511498b8ead55 to your computer and use it in GitHub Desktop.
Save cybrox/c0f4f55dad55a86bb0e511498b8ead55 to your computer and use it in GitHub Desktop.
defmodule RaymanPlayground.Application do
@moduledoc false
use Application
def start(_type, _args) do
{:ok, pid} = :gen_tcp.listen(1883, [
:binary,
active: false,
reuseaddr: true
])
server = spawn(fn ->
await_connection(pid)
end)
{:ok, server}
end
defp await_connection(pid) do
{:ok, client} = :gen_tcp.accept(pid)
read_data(client)
await_connection(pid)
end
defp read_data(client) do
{:ok, data} = :gen_tcp.recv(client, 0)
Rayman.decode_packet(data)
read_data(client)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment