- prepare for py3

This commit is contained in:
liris
2013-02-19 10:48:44 +09:00
parent 4e0cf4bf36
commit ed7041ae8c
3 changed files with 20 additions and 16 deletions

View File

@@ -3,10 +3,10 @@ import websocket
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.create_connection("ws://echo.websocket.org/")
print "Sending 'Hello, World'..."
print("Sending 'Hello, World'...")
ws.send("Hello, World")
print "Sent"
print "Receiving..."
result = ws.recv()
print "Received '%s'" % result
print("Sent")
print("Receiving...")
result = ws.recv()
print("Received '%s'" % result)
ws.close()

View File

@@ -3,28 +3,32 @@ import thread
import time
import sys
def on_message(ws, message):
print message
print(message)
def on_error(ws, error):
print error
print(error)
def on_close(ws):
print "### closed ###"
print("### closed ###")
def on_open(ws):
def run(*args):
for i in range(3):
# send the message, then wait
# send the message, then wait
# so thread doesnt exit and socket
# isnt closed
ws.send("Hello %d" % i)
time.sleep(1)
time.sleep(1)
ws.close()
print "Thread terminating..."
print("Thread terminating...")
thread.start_new_thread(run, ())
if __name__ == "__main__":

View File

@@ -765,10 +765,10 @@ class WebSocketApp(object):
if __name__ == "__main__":
enableTrace(True)
ws = create_connection("ws://echo.websocket.org/")
print "Sending 'Hello, World'..."
print("Sending 'Hello, World'...")
ws.send("Hello, World")
print "Sent"
print "Receiving..."
print("Sent")
print("Receiving...")
result = ws.recv()
print "Received '%s'" % result
print("Received '%s'" % result)
ws.close()