I want to programmatically find the size of the socket waiting queue of my computer i.e. the number of socket that can be put in the queue before being refused (while the server is listening for clients).
On the server side, I simply create a socket, bind it, listen and enter in an infinite loop in order to wait client sockets.
Then I thought that this little script would help me to find the queue size:
pids=""
for i in {1..8}; do
netcat localhost -w 3 19677 &
pids+=" $!"
done
for p in $pids; do
if wait $p; then
echo "Process $p success"
else
echo "Process $p fail"
fi
done
If there is more than 4 rounds in the loop then I always get a timeout exception,(and never for 4 or less) but increasing the number of rounds doesn't always lead to more errors (I don't always get 2 errors for 6 rounds, 3 for 7, etc.). Why?
Moreover, if I launch netcat directly in 5 terminals (netcat localhost -w 5 19677
), I don't get any error.
What am I missing?