Skip to content

Commit 94ccc36

Browse files
committed
fixing client demos
1 parent 98a7095 commit 94ccc36

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

ws4py/client/geventclient.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def receive(self):
9494

9595
if __name__ == '__main__':
9696

97-
ws = WebSocketClient('http://localhost:9000/ws', protocols=['http-only', 'chat'])
97+
ws = WebSocketClient('ws://localhost:9000/ws', protocols=['http-only', 'chat'])
9898
ws.connect()
9999

100100
ws.send("Hello world")
@@ -107,8 +107,9 @@ def incoming():
107107
while True:
108108
m = ws.receive()
109109
if m is not None:
110-
print((m, len(str(m))))
111-
if len(str(m)) == 35:
110+
m = str(m)
111+
print((m, len(m)))
112+
if len(m) == 35:
112113
ws.close()
113114
break
114115
else:

ws4py/client/threadedclient.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,25 @@ def handshake_ok(self):
5757
"""
5858
self._th.start()
5959
self._th.join(timeout=1.0)
60+
61+
if __name__ == '__main__':
62+
from ws4py.client.threadedclient import WebSocketClient
63+
64+
class EchoClient(WebSocketClient):
65+
def opened(self):
66+
for i in range(0, 200, 25):
67+
self.send("*" * i)
68+
69+
def closed(self, code, reason):
70+
print(("Closed down", code, reason))
71+
72+
def received_message(self, m):
73+
print("=> %d %s" % (len(m), str(m)))
74+
if len(m) == 175:
75+
self.close(reason='bye bye')
76+
77+
try:
78+
ws = EchoClient('ws://localhost:9000/ws', protocols=['http-only', 'chat'])
79+
ws.connect()
80+
except KeyboardInterrupt:
81+
ws.close()

0 commit comments

Comments
 (0)