Skip to content

Instantly share code, notes, and snippets.

@kyle-eshares
Created March 1, 2016 17:19
Show Gist options
  • Save kyle-eshares/963521dc6e56438e5adc to your computer and use it in GitHub Desktop.
Save kyle-eshares/963521dc6e56438e5adc to your computer and use it in GitHub Desktop.
defmodule SimpleTCP.Sender do
use GenServer
import Socket
def start_link(socket, opts \\ []) do
GenServer.start_link(__MODULE__, [socket: socket], opts)
end
def init(socket) do
# Register the process with gproc and subcscribe to :something
:gproc.reg({:p, :l, :something})
{:ok, socket}
end
def handle_cast({:msg, msg}, [socket: socket] = state) do
Socket.Stream.send(socket, msg)
{:noreply, state}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment