That's not the "every 10 seconds" called for.
How do you expect the heartbeat process to act? If the heartbeat arrives before 9.9999999999999999999999999999 seconds or after 10.00000000000000000000000001 seconds, the other end is considered dead?
Typical heartbeat implementation need to get a heartbeat within a certain timeout.
See it? The source/destination pairs are the same in both directions (Ie. for the client to server heartbeats and the server to client transfers) which makes the question of whether two local processes can use the same local port concurrently very relevant!
Sure, if you assume the server and client are the same machine. As I understand, there are 8 one-way connections:
- client:53036 to server:8020
- client:53037 to server:8019
- client:53038 to server:8008
- client:53039 to server:8003
- server:8020 to client:53036
- server:8019 to client:53037
- server:8008 to client:53038
- server:8003 to client:53039
I fail to see why that leads to two processes using the same port.
And if these are two separate processes, how will the heartbeat process know when the read process is between reads?
Why should it have to know? It's just a heartbeat. The OP didn't state such a requirement, so why should I assume one?
Use short reads with UDP and data gets thrown way.
With short reads, I mean, "don't keep reading packets until there's nothing waiting before checking the time again". I'm not assuming the OP manages to create UDP packets that are so big, it takes more than 10 seconds to read one packet.
You made two suggestions in that post, the second of which used multiple processes, with separate processes for the heartbeats and data transfers.
I wouldn't describe my second suggestion a sketch. But anyway, that suggestion uses 8 processes, each focussing on one port, all different.