One thread could also simply be dedicated to sending heartbeats every 10 seconds. If you think that this might interfere with data transfer, record the timestamp each time you send a message to any port, and have the heartbeat process read it. I would have the heartbeat timer internally set for 3 seconds in this case so that it could always be sure to send a message to any of the ports while not allowing the 10-second window to expire for any. But since you’re not talking about hundreds of ports here, almost any similar design will do.