I'm writing a program in Java that needs to maintain communication with some 30 pc's (and maybe more in future) but with small packages (below 1-2 Kb). My program needs to know when one comp goes offline without send any notice (if crash for example) so I think that I have two options:
1) If I use UDP datagrams it's more convenient for faster communication, but I think that I'll need to check every amount of seconds If all PC's are still online.
2) If I use TCP sockets, I can know more easily if a PC goes offline because of broken TCP connection, don't?, or I still need to check?.
Anyone can help me to know what it's more memory and cpu time consuming between use UDP Datagrams and TCP sockets in this case?, or if I'm totally wrong or even if there's a better solution .
What you're doing is typically called a 'heartbeat' - it's very common. You can google that if it helps.
I think the last time I implemented any sort of heartbeat message it was over tcp, because tcp has guarenteed delivery (you don't want alarms going off due to a lost udp packet).
Either one is not going to affect memory/cpu usage as it's all I/O.
Thanks! I'll take in consideration about TCP using and google more about it .