add a looping write utility for writing to socket