Unix sockets demo

This commit is contained in:
Imbus 2025-06-25 07:24:39 +02:00
parent e07b9a5eff
commit 1a505c032e
5 changed files with 234 additions and 0 deletions

26
socket/test.sh Normal file
View file

@ -0,0 +1,26 @@
#!/bin/bash
SOCKET_PATH="/tmp/demosocket"
# Cleanup function to be run on exit
cleanup() {
echo "Cleaning up..."
if [[ -n "$SERVER_PID" ]]; then
kill "$SERVER_PID" 2>/dev/null || true
wait "$SERVER_PID" 2>/dev/null || true
fi
rm -f "$SOCKET_PATH"
}
# Trap EXIT to ensure cleanup runs
trap cleanup EXIT
echo "Starting server..."
./server.elf &
SERVER_PID=$!
# Wait briefly for the server to start
sleep 0.2
echo "Running client..."
./client.elf