It might be overkill for what you're doing, but you could look into using
TCP[
^], it has some basic error checking and recovery built in, and there should be plenty of support for it in C (
this[
^] has some sample code, though I don't have any experience in using TCP directly so I have no idea if it's any good, but Google turned up over 61 million results for "tcp in c").