ycv005
Handling PID of Genserver in params and HTML.eex template
Following is my PID while printing in log
IO.puts("++++++pid")
IO.inspect(pid)
as result I am getting
++++++pid
#PID<0.9069.0>
I am pasisng this PID in following ways-
1- inserting into session and render to live view
2- From live view passing it to html
3- Then Html to a controller.
Now, what happens I am getting error as following-
protocol Phoenix.Param not implemented for #PID<0.9069.0>. This protocol is implemented for: Map, BitString, Atom, Integer, Any
Now, I want to pass this PID as I have to used it later on. And to do so, I must ensure that it pass well in params as well as other places. How can I do this? Any help will be appreciated.
Most Liked
NobbZ
Again, you shall not use the pid to send it between client and server, it is not properly deserializable.
You can use though an atom as name for the GenServer though and send it to the client. But this does not scale well.
Better were to use Registry and :via tuples to name the GenServer on start. Then you can send the moving parts of the :via tuple to the client (perhaps a session id or something like that) and reconstruct the tuple on the server.
NobbZ
PIDs are mainly opaque, even though you could send its textual representation to the client, you weren’t be able to get back a PID from it on the server side.
If you really need your client to know the “address” of a certain GenServer, rather than letting the server know which of the running GenServers is responsible for the users session, then use a symbolic name and Registry.
NobbZ
Then you can just use the identifier when calling GenServer.call/GenServer.cast.
Both functions can deal with pids or with whatever :name you gave the GenServer when starting it.







