- prepare for py3
This commit is contained in:
		@@ -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()
 | 
			
		||||
 
 | 
			
		||||
@@ -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__":
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user