What are socket handler?

Hi all
I am trying to understand how channel works and read the doc on phoenixframework.
I started with socket handlers and could not understand this setence:

Phoenix holds a single connection to the server and multiplexes your channel sockets over that one connection.

What for server does it mean here?

Thanks

1 Like

It means that when the javascript webpage opens a websocket connection to the server then the server opens a single actor/process to manage that connection and authentication. Any time the client opens a new topic it goes through that socket process and that socket process then creates topic-specific processes for that client, I.E. it multiplexes out the topic connections through the single socket connection. :slight_smile:

1 Like

So please check, if I understand what you mean:

The server creates for every socket connection a process right? If 5 users connect to the server, then the server will create 5 processes?

When a user writes something into the topic, then the topic specific process will broadcast to other 4 users through which socket?

What do you mean here:
it multiplexes out the topic connections through the single socket connection.

Can you please draw it for better understanding?

1 Like

Each user has their own connection to the server. Each connection has it’s own process on the server, holding the socket for that connection. A user can be connected to multiple topics, but all communication for those topics goes over the one socket, which is what is meant by “multiplexed”. When a message is broadcasted to all users of a topic, the message is sent over every socket associated with a user joined to that topic. Make sense?

4 Likes

It makes sense. Thanks so much.

1 Like