Add error catching that prevents seg faults in receive and send.