Skip to content

How to make a longlive connection client ? #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lowkey2016 opened this issue Feb 11, 2018 · 1 comment
Closed

How to make a longlive connection client ? #344

lowkey2016 opened this issue Feb 11, 2018 · 1 comment

Comments

@lowkey2016
Copy link

lowkey2016 commented Feb 11, 2018

Just like this:

if __name__ == "__main__":
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp("ws://echo.websocket.org/",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = on_open
    ws.run_forever()

https://github.com/websocket-client/websocket-client#long-lived-connection

@aaugustin
Copy link
Member

aaugustin commented Feb 11, 2018

#!/usr/bin/env python

import asyncio
import websockets

async def noop(uri):
    async with websockets.connect(uri) as websocket:
        async for message in websocket:
            pass

asyncio.get_event_loop().run_until_complete(
    noop('ws://echo.websocket.org/'))

PS - You're showing an example with callbacks. websockets operates at a higher level. You must forget about callbacks and learn coroutines (or choose a less advanced library).

@aaugustin aaugustin mentioned this issue Jun 23, 2019
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants