I want to send a message directly to a target socket, without using EndPoint.Broadcast or erlang :PG2
(it’s not a correct way to call getMemberList, then iterate and filter out a single pid for each message sent)
however using a code as (in handle_in callback):
socket_pid = self()
send(socket_pid, “TEST”) #trying to send a message to myself
[error] Ranch listener IperiusAppWeb.Endpoint.HTTP had connection process started with :cowboy_clear:start_link/4 at #PID<0.461.0> exit with reason: {:function_clause, [{Phoenix.Endpoint.Cowboy2Handler, :handle_reply, [IperiusAppWeb.Sockets.ChatSocket, {:text, “{“1”:“2”}”}], []},
def handle_in({text, _opts}, state) do
socket_pid = self()
send(socket_pid, {:text, Jason.encode!(%{“1” => “2”})}) # I’m trying to send a test message to myself
This is a Module Function Args tuple, a common idiom in BEAM code. In this case, it means the missing function head was Phoenix.Endpoint.Cowboy2Handler.handle_reply…
With two arguments: your handler module, and the value passed to send in your example above.
The error appears to be arising from this code, in the Cowboy 2 handler:
which is responsible for passing messages sent to the process into your module.
Your handle_in function returns the value of the last expression in it, the send call. But Phoenix.Endpoint.Cowboy2Handler.handle_reply only supports a fixed set of reply shapes: