routine safe tcp read write