Skip to content

Pub/Sub Example? #46

Answered by cirospaciari
johnnytolengo asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @johnnytolengo we have some examples in
https://github.com/cirospaciari/socketify.py/tree/main/examples
Chat app example use pub/sub

And also in:
https://github.com/cirospaciari/socketify.py/tree/main/bench/websockets

See the example bellow as used in benchmark, you can use ws.subscribe(topic) and ws.unsusbscribe(topic) and use app.publish(topic, message, opcode) to broadcasting the message to the subscribed clients

 from socketify import App, AppOptions, OpCode, CompressOptions

remaining_clients = 16
app = App(websocket_factory_max_itens=1_500_000)


def ws_open(ws):
    ws.subscribe("room")
    global remaining_clients
    remaining_clients = remaining_clients - 1
    if remainin…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by cirospaciari
Comment options

You must be logged in to vote
1 reply
@cirospaciari
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #45 on December 06, 2022 21:21.