-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle ping/pong action, plus Github Action for Relase
- Loading branch information
1 parent
905d2b5
commit 93ebb25
Showing
7 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Build and Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
build-linux: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
target: x86_64-unknown-linux-gnu | ||
override: true | ||
|
||
- name: Build | ||
run: | | ||
cargo build --release --target x86_64-unknown-linux-gnu | ||
tar -czf anypay-websockets-linux-x86_64.tar.gz -C target/x86_64-unknown-linux-gnu/release anypay-websockets | ||
- name: Create Release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
files: | | ||
anypay-websockets-linux-x86_64.tar.gz | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: anypay-websockets-linux-x86_64 | ||
path: target/x86_64-unknown-linux-gnu/release/anypay-websockets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
import asyncio | ||
import websockets | ||
import json | ||
from datetime import datetime | ||
|
||
async def test_ping(): | ||
try: | ||
# Connect to WebSocket server | ||
async with websockets.connect('ws://localhost:8080') as websocket: | ||
# Create ping message | ||
ping_message = { | ||
"action": "ping" | ||
} | ||
|
||
print("Sending ping...") | ||
await websocket.send(json.dumps(ping_message)) | ||
|
||
# Wait for pong response | ||
response = await websocket.recv() | ||
response_data = json.loads(response) | ||
|
||
print(f"Received response: {response_data}") | ||
|
||
# Validate response | ||
if (response_data.get('type') == 'pong' and | ||
response_data.get('status') == 'success' and | ||
'timestamp' in response_data): | ||
|
||
# Convert timestamp to readable format | ||
timestamp = datetime.fromtimestamp(response_data['timestamp']) | ||
print(f"✅ Received pong at {timestamp}") | ||
print(f"Round trip latency: {datetime.utcnow().timestamp() - response_data['timestamp']}s") | ||
else: | ||
print("❌ Invalid pong response:", response_data) | ||
|
||
except Exception as e: | ||
print(f"❌ Error: {e}") | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(test_ping()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters