Add explicit ping/pong message handling to Python implementations

- Implement ping/pong event handlers in wsscp.py and wsssh.py
- Register ping_handler and pong_handler functions for WebSocket connections
- Enable debug logging for ping/pong events when debug mode is enabled
- Maintain automatic pong responses via websockets library while adding explicit handling
parent e230ee7c
...@@ -101,6 +101,16 @@ async def run_scp(server_ip, server_port, client_id, local_port, scp_args): ...@@ -101,6 +101,16 @@ async def run_scp(server_ip, server_port, client_id, local_port, scp_args):
try: try:
async with websockets.connect(uri, ssl=ssl_context) as websocket: async with websockets.connect(uri, ssl=ssl_context) as websocket:
# Set up ping/pong handlers for explicit handling
async def ping_handler(payload):
if debug: print(f"[DEBUG] Received ping: {payload}")
# Pong is sent automatically by websockets library
async def pong_handler(payload):
if debug: print(f"[DEBUG] Received pong: {payload}")
websocket.ping_handler = ping_handler
websocket.pong_handler = pong_handler
# Request tunnel # Request tunnel
await websocket.send(json.dumps({ await websocket.send(json.dumps({
"type": "tunnel_request", "type": "tunnel_request",
......
...@@ -101,6 +101,16 @@ async def run_ssh(server_ip, server_port, client_id, local_port, ssh_args): ...@@ -101,6 +101,16 @@ async def run_ssh(server_ip, server_port, client_id, local_port, ssh_args):
try: try:
async with websockets.connect(uri, ssl=ssl_context) as websocket: async with websockets.connect(uri, ssl=ssl_context) as websocket:
# Set up ping/pong handlers for explicit handling
async def ping_handler(payload):
if debug: print(f"[DEBUG] Received ping: {payload}")
# Pong is sent automatically by websockets library
async def pong_handler(payload):
if debug: print(f"[DEBUG] Received pong: {payload}")
websocket.ping_handler = ping_handler
websocket.pong_handler = pong_handler
# Request tunnel # Request tunnel
await websocket.send(json.dumps({ await websocket.send(json.dumps({
"type": "tunnel_request", "type": "tunnel_request",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment