Reading from a file a background program writes to

Hi!

#!/usr/bin/env bash
rm tmpcomm
nc -v -u -l 444 | hexdump -b  > tmpcomm
while :
do
    read l1 < tmpcomm
    read l2 < tmpcomm
    read l3 < tmpcomm
    read l4 < tmpcomm
 
    # do something
done

I start netcat in the background and listen for an incoming conncetion. All incoming connections write exactly four lines of hexdata in the file tmpcomm.
Now I want to read these four lines out again and do something with them. If no connection is coming in, the script should block.
Especially I want something like "For every connection, do something with the input and send a message back again".

But at the moment I have an endless loop in my script :frowning:

One naive way is to check for the file size unless you are not truncating the file