Skip to content

@jeregrine /readme.md secret
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  1. browse to localhost:5000
  2. open javascript console
  3. ws = new WebSocket("ws://localhost:5000/my_websocket")
  4. ws.onmessage = function(resp){console.log(resp.data)}
  5. ws.send("Hey")
defmodule Totem.Router do
use Phoenix.Router, port: 5000
resources "/user", UserController
websocket "/my_websocket", Totem.SocketController
end
defmodule Totem.SocketController do
use Phoenix.Controller.Websocket
def start(_transport, socket, _state) do
:erlang.start_timer(1000, self(), "Hello!")
IO.puts "INIT"
:ok
end
def stream(_data, socket, _state) do
IO.puts "RECIEVED DATA"
reply socket, {:text, "Thats what she said!"}
end
def info({:timeout, _ref, msg}, socket, _state) do
IO.puts "TIMEOUT SENDING DATA"
reply socket, {:text, msg}
:erlang.start_timer(1000, self(), "How' you doin'?")
end
def closed(reason, _req, _state) do
IO.inspect reason
:ok
end
end
@benjamintanweihao

I am so looking forward for this to be merged to master!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.