Phoenix websocket 1:1 messaging

hello, sorry me, I’m a newbie

studying websocket phoenix channels, pubsub, transport

easy for broadcasting, but for 1:1 websocket messaging?

In C or in Pascal I will use an hash table, or dictionary, to associate the handle of the socket to a username, then when someone send to another simply will lookup the username to retrieve the socket then sending

In elixir/phoenix what is the most direct mode to achieve this one to one communication? (as example associating pid of the process/socket to a username?)

thank yuo

1 Like


also I want to access at lower level to the websocket json packet, both read and write, eg. to put a json value before send, or to retrieve all the passed headers/infos into the socket/pid/descriptor map/struct

1 Like

Implement in your MyAppWeb.UserSocket module:

You can look at serializers for this one:

But keep in mind that phoenix channels are an abstraction on top of multiple transports and not just websockets. If you want low level websocket handling you’re likely better of integrating directly with cowboy.

1 Like

You still want to use phoenix channels and pubsub. If I’m messaging you, and open two tabs, that’s no longer 1:1. There are two subscribed channels for me, you need pubsub.


in this case I will build a mini parser into js to use one only tcp channel and many windows (eg. label, msg), then on server parse from, label, msg?