Prevent client send message to server in phoenix channel

Client just only subscribe channel, how to prevent client sending message to server ?

You cannot, because WebSockets are bidirectional. But you can just ignore the messages on the server, or implement access control so that only messages from certain clients are accepted.

Technically I think you could implement your own transport that would prevent sending from client, but that would be a lot of work for dubious benefit.

ok i am just curious what if client spam the server with publish large message

If the client is not supposed to send messages, you could disconnect it if it does for example, or ban the IP.

Although, as suggested, there’s ways you can artificially limit websockets to only allow receiving messages by the client, they’re designed specifically to allow bi-directional messaging between clients and servers. If you do not want that bi-directional flow the best solution would be to go with something like Server Side Events, which are designed specifically to handle server->client uni-directional messaging.

ok thanks for all answer