robot_cleaning_game/backend/test-server.sh

61 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
# Simple UDP test script for the game server
# Sends registration from two players on specific ports and receives responses
HOST="localhost"
SERVER_PORT=9999
echo "Testing game server at $HOST:$SERVER_PORT"
RESPONSE1=$(mktemp)
# RESPONSE2=$(mktemp)
echo "=== Listener on port 12345 ==="
nc -u -l 127.0.0.1 12345 > "$RESPONSE1" &
PID1=$!
sleep 3
trap "rm -f $RESPONSE1 $RESPONSE2; jobs -p | xargs kill -9 2>/dev/null" EXIT
# echo ""
# # Create temp files for responses
# RESPONSE1=$(mktemp)
# RESPONSE2=$(mktemp)
# # Cleanup on exit
# trap "rm -f $RESPONSE1 $RESPONSE2; jobs -p | xargs kill -9 2>/dev/null" EXIT
# echo "=== Starting Player 1 listener on port 12345 ==="
# nc -u -l 127.0.0.1 12345 > "$RESPONSE1" 2>/dev/null &
# PID1=$!
# sleep 0.3
# echo "=== Starting Player 2 listener on port 12346 ==="
# nc -u -l 127.0.0.1 12346 > "$RESPONSE2" 2>/dev/null &
# PID2=$!
# sleep 0.3
# echo ""
# echo "=== Sending REGISTER from Player 1 (port 12345) ==="
# echo -n "REGISTER" | nc -u -w1 -p 12345 "$HOST" "$SERVER_PORT"
# sleep 0.5
# echo "=== Sending REGISTER from Player 2 (port 12346) ==="
# echo -n "REGISTER" | nc -u -w1 -p 12346 "$HOST" "$SERVER_PORT"
# sleep 1
# echo ""
# echo "=== Stopping listeners ==="
# kill $PID1 $PID2 2>/dev/null
# sleep 0.2
# echo ""
# echo "=== Results ==="
# echo "Player 1 response:"
# cat "$RESPONSE1"
# echo ""
# echo "Player 2 response:"
# cat "$RESPONSE2"
# echo ""
echo "Done!"