凤凰城 - 无法从iex广播到频道

时间:2016-08-29 10:34:19

标签: elixir phoenix-framework

我尝试通过以下方式打开IEX:iex -S mix和iex -S mix phoenix.server

这是我的user_socket:

defmodule Final.UserSocket do
  use Phoenix.Socket

  channel "keywords*", Final.KeywordsChannel 
  transport :websocket, Phoenix.Transports.WebSocket  

  def connect(_params, socket) do
      {:ok, socket}
    end
  def id(_socket), do: nil  

end

和关键字渠道:

defmodule Final.KeywordsChannel do
  use Final.Web, :channel
  use Phoenix.Channel      

  def join("keywords",_, socket) do
    IO.puts "helloo"
     {:ok, "aaaa", socket}
  end

  def handle_in("new_msg", %{"body" => body}, socket) do
    IO.puts "hello"
    broadcast! socket, "new_msg", %{body: body}
    {:noreply, socket}
  end

  def handle_out("new_msg", payload, socket) do
    IO.puts "hell"
    push socket, "new_msg", payload
    {:noreply, socket}
  end


end

我试着称之为:

Final.Endpoint.broadcast(“keywords”,“new_msg”,%{body:“b”})

Final.Endpoint.broadcast! “keywords”,“new_msg”,%{body:“b”} ...

我能想到的所有其他变化,但从未收到任何回应,只是“:ok”

使用1.3.2 elixir和phoenix 1.2.1

0 个答案:

没有答案