forked from Lawouach/WebSocket-for-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho_client.py
More file actions
30 lines (24 loc) · 824 Bytes
/
Copy pathecho_client.py
File metadata and controls
30 lines (24 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-
from ws4py.client.threadedclient import WebSocketClient
class EchoClient(WebSocketClient):
def opened(self):
def data_provider():
for i in range(1, 200, 25):
yield "#" * i
self.send(data_provider())
for i in range(0, 200, 25):
print(i)
self.send("*" * i)
def closed(self, code, reason):
print(("Closed down", code, reason))
def received_message(self, m):
print("=> %d %s" % (len(m), str(m)))
if len(m) == 175:
self.close(reason='Bye bye')
if __name__ == '__main__':
try:
ws = EchoClient('ws://localhost:9000/ws', protocols=['http-only', 'chat'])
ws.daemon = False
ws.connect()
except KeyboardInterrupt:
ws.close()