Skip to content
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

断线重连怎么做? #237

Open
54huige opened this issue Jan 19, 2018 · 2 comments
Open

断线重连怎么做? #237

54huige opened this issue Jan 19, 2018 · 2 comments

Comments

@54huige
Copy link

54huige commented Jan 19, 2018

from ws4py.client.threadedclient import WebSocketClient
from ws4py.exc import HandshakeError
class DummyClient(WebSocketClient):
def opened(self):
self.send(input('请输入你想说的话:'))

def closed(self, code, reason=None):
    #print("Closed down", code, reason)
    print("Closed down")


def received_message(self, m):
    print (m)

if name == 'main':
try:
ws = DummyClient('ws://'+input('请输入ws地址连接:'), protocols=['chat'])
ws.connect()
ws.run_forever()
except KeyboardInterrupt:
ws.close()

@jeffcumt
Copy link

同求,我在配合爬虫使用的时候,运行几个小时后,会报1006going away的错误,然后关闭了

@laiyazhou
Copy link

    count = 0
    while True: 
    try: 
        ws = WSClient('xxx') 
        print("Start contenting...") 
        ws.connect() 
        ws.run_forever() 
    except KeyboardInterrupt: 
        ws.close() 
        break 
    except Exception as e: 
        count += 1 
        print(e, "Try again %s times..." % count) 
        continue

I hope it helps you

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

3 participants