Rewritten to use only one thread for socket communication.
Uses conditional variables for waits.
Still have a problem with callhome2, but callhome1 always seems to work.