- 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__": if __name__ == "__main__":
websocket.enableTrace(True) websocket.enableTrace(True)
ws = websocket.create_connection("ws://echo.websocket.org/") ws = websocket.create_connection("ws://echo.websocket.org/")
print "Sending 'Hello, World'..." print("Sending 'Hello, World'...")
ws.send("Hello, World") ws.send("Hello, World")
print "Sent" print("Sent")
print "Receiving..." print("Receiving...")
result = ws.recv() result = ws.recv()
print "Received '%s'" % result print("Received '%s'" % result)
ws.close() ws.close()

View File

@@ -3,14 +3,18 @@ import thread
import time import time
import sys import sys
def on_message(ws, message): def on_message(ws, message):
print message print(message)
def on_error(ws, error): def on_error(ws, error):
print error print(error)
def on_close(ws): def on_close(ws):
print "### closed ###" print("### closed ###")
def on_open(ws): def on_open(ws):
def run(*args): def run(*args):
@@ -23,7 +27,7 @@ def on_open(ws):
time.sleep(1) time.sleep(1)
ws.close() ws.close()
print "Thread terminating..." print("Thread terminating...")
thread.start_new_thread(run, ()) thread.start_new_thread(run, ())

View File

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