github sparckles/Robyn v0.9.0
v0.9.0 | WebSockets

latest releases: v0.72.2, v0.72.1, v0.72.0...
3 years ago

Websocket Intergration

PR Links

Full Changelog: v0.8.0...v0.9.0

Robyn supports WebSockets now.

from robyn import Robyn, WS

app = Robyn(__file__)
websocket = WS(app, "/web_socket")
i = -1

@websocket.on("message")
def connect():
    global i
    i+=1
    if i==0:
        return "Whaaat??"
    elif i==1:
        return "Whooo??"
    elif i==2:
        i = -1
        return "*chika* *chika* Slim Shady."
        
@websocket.on("close")
def close():
    print("Hello world")
    return "Hello world, from ws"

@websocket.on("connect")
def message():
    print("Hello world")
    return "Hello world, from ws"
        

You can have 3 methods for every web socket:

"message", "close" and "connect" for responding to the message received, connection closed and connection initiated.

Don't miss a new Robyn release

NewReleases is sending notifications on new releases.