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
25 lines (20 loc) · 705 Bytes
/
Copy pathecho_client.py
File metadata and controls
25 lines (20 loc) · 705 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
# -*- coding: utf-8 -*-
from ws4py.client.threadedclient import WebSocketClient
class EchoClient(WebSocketClient):
def opened(self, protocols, extensions):
def data_provider():
for i in range(1, 200, 25):
yield "#" * i
self.send(data_provider())
for i in range(0, 200, 25):
self.send("*" * i)
def received_message(self, m):
print m, len(str(m))
if len(str(m)) == 175:
self.close()
if __name__ == '__main__':
try:
ws = EchoClient('http://localhost:9000/ws', protocols=['http-only', 'chat'])
ws.connect()
except KeyboardInterrupt:
ws.close()