tuxmartin

ws

Feb 12th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. # https://pypi.python.org/pypi/websocket-client/
  2.  
  3. import websocket
  4. import thread
  5. import time
  6.  
  7. def on_message(ws, message):
  8.     print "Prisla data:"
  9.     print message
  10.  
  11. def on_error(ws, error):
  12.     print error
  13.  
  14. def on_close(ws):
  15.     print "### closed ###"
  16.  
  17. def on_open(ws):
  18.     def run():
  19.         print "Start..."
  20.         ws.send("Test")
  21.         time.sleep(1)
  22.         #ws.close()
  23.         print "thread terminating..."
  24.     thread.start_new_thread(run, ())
  25.  
  26.  
  27. if __name__ == "__main__":
  28.     websocket.enableTrace(True)
  29.     ws = websocket.WebSocketApp("ws://194.228.153.100:9000/ws/text/75?access_token=67bde5d1b5f14520a565d03deae877fb",
  30.                               on_message = on_message,
  31.                               on_error = on_error,
  32.                               on_close = on_close)
  33.     ws.on_open = on_open
  34.     ws.run_forever()
Advertisement
Add Comment
Please, Sign In to add comment