|
| 1 | + |
| 2 | +import websocket |
| 3 | +import _thread |
| 4 | +import time |
| 5 | + |
| 6 | +def on_message(wsapp, message): |
| 7 | + print(f"got message: {message}") |
| 8 | + |
| 9 | +def on_ping(wsapp, message): |
| 10 | + print("Got a ping! A pong reply has already been automatically sent.") |
| 11 | + |
| 12 | +def on_pong(wsapp, message): |
| 13 | + print("Got a pong! No need to respond") |
| 14 | + |
| 15 | + |
| 16 | +def on_error(wsapp, message): |
| 17 | + print(f"Got error: {message}") |
| 18 | + |
| 19 | + |
| 20 | +#wsapp = websocket.WebSocketApp("wss://testnet.binance.vision/ws/btcusdt@trade", on_message=on_message, on_ping=on_ping, on_pong=on_pong, on_error=on_error) |
| 21 | + |
| 22 | +#wsapp = websocket.WebSocketApp("wss://echo.websocket.events", on_message=on_message, on_ping=on_ping, on_pong=on_pong, on_error=on_error) |
| 23 | + |
| 24 | +wsapp = websocket.WebSocketApp("wss://relay.damus.io", on_message=on_message, on_ping=on_ping, on_pong=on_pong, on_error=on_error) |
| 25 | + |
| 26 | +#wsapp = websocket.WebSocketApp("wss://relay.primal.net", on_message=on_message, on_ping=on_ping, on_pong=on_pong, on_error=on_error) |
| 27 | + |
| 28 | + |
| 29 | +def stress_test_thread(): |
| 30 | + print("before run_forever") |
| 31 | + #wsapp.run_forever(ping_interval=30, ping_timeout=10) |
| 32 | + #wsapp.run_forever(ping_interval=300, ping_timeout=10, ping_payload="This is an optional ping payload") |
| 33 | + wsapp.run_forever() |
| 34 | + print("after run_forever") |
| 35 | + |
| 36 | +_thread.stack_size(32*1024) |
| 37 | +_thread.start_new_thread(stress_test_thread, ()) |
| 38 | + |
| 39 | +time.sleep(5) |
| 40 | +print("sending it") |
| 41 | +# nothing: |
| 42 | +#wsapp.send_text('["REQ", "ihopethisworks3", {"kinds": [1], "authors": "04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9"}]') |
| 43 | +#wsapp.send_text('["REQ", "ihopethisworks3", {"kinds": [1] }]') |
| 44 | +# this worked at some point: |
| 45 | +#wsapp.send_text('["REQ","index3",{"kinds":[9735]}]') |
| 46 | +#wsapp.send_text('["REQ","index3",{"kinds":[9735], "since": 1745086888}]') |
| 47 | +tosend = '["REQ","index3",{"kinds":[9735], "since": ' |
| 48 | +tosend += str(round(time.time()-1000)) |
| 49 | +tosend += '}]' |
| 50 | +print(f"sending: {tosend}") |
| 51 | +wsapp.send_text(tosend) |
| 52 | +#1745086888 |
| 53 | +#["REQ","index",{"kinds":[9735]}] |
| 54 | + |
| 55 | + |
| 56 | +print("waiting 30 seconds...") |
| 57 | +time.sleep(30) |
| 58 | +#print("sending again") |
| 59 | +#wsapp.send_text('again') |
| 60 | + |
| 61 | + |
| 62 | +time.sleep(25) |
| 63 | +#print("sending more") |
| 64 | +#wsapp.send_text('more') |
| 65 | + |
| 66 | +wsapp.close() |
| 67 | + |
| 68 | + |
0 commit comments